[英]Python can't import packages even though its installed via pip
Really struggling with this one, so any help would be greatly appreciated.真的很努力解决这个问题,所以任何帮助将不胜感激。
I can't seem to install any packages...我似乎无法安装任何软件包...
But if I then try to import...但是,如果我然后尝试导入...
I'm guessing that it's something to do with where the downloads should be located but I can't figure out where they should be.我猜这与下载的位置有关,但我不知道它们应该在哪里。
Thank you谢谢
Thanks to everyone that helped.感谢所有帮助过的人。
For anyone with the same problem, not sure its the ideal solution, but I was using Spyder directly (not through Anaconda).对于任何有同样问题的人,不确定它是否是理想的解决方案,但我直接使用 Spyder(而不是通过 Anaconda)。 So instead I downloaded Anaconda then installed pygame (any package) via the 'anaconda prompt' and not the cmd, did the trick.
因此,我下载了 Anaconda,然后通过“anaconda 提示”而不是 cmd 安装了 pygame(任何包),成功了。
if you have more than one python install there could be some confusion between the python
and pip
commands.如果您安装了多个 python,则
python
和pip
命令之间可能会有些混淆。
check pip is installing with the same python command by running:通过运行以下命令检查 pip 是否使用相同的 python 命令安装:
python -m pip install pygame
and from python
check the site-packages locations to verify the install;并从
python
检查站点包位置以验证安装; see this answer for details: How do I find the location of my Python site-packages directory?有关详细信息,请参阅此答案: 如何找到我的 Python 站点包目录的位置?
You'll probably find spyder is setting some paths differently.你可能会发现 spyder 设置了一些不同的路径。
You installed pygame for your python interpreter but you are specifying your script run from IPython - I never use spyder b/c that's an extra layer of complication I don't need, but you should probably check what interpreter spyder is running您为 python 解释器安装了 pygame,但您指定从 IPython 运行脚本 - 我从不使用 spyder b/c,这是我不需要的额外复杂层,但您可能应该检查什么解释器 spyder 正在运行
and in that prompt (shown in links below) either specify the 'normal' interpreter (the one for which 'pip install XXX' will install XXX for, that is c\users\jason...python39).并在该提示中(如下链接所示)指定“普通”解释器(“pip install XXX”将为其安装 XXX 的解释器,即 c\users\jason...python39)。 Or you could do what some other people say and use conda instead of pip to install pygame to your spyder environment.
或者您可以按照其他人的说法使用 conda 而不是 pip 将 pygame 安装到您的 spyder 环境中。 Once again spyder/anaconda/ipython is a big wtfwhy for me, and haven't used it in many years, but from my understanding conda is like a parallel package manager to pip, but for anaconda setup.
再次 spyder/anaconda/ipython 对我来说是一个很大的 wtfwhy,并且已经很多年没有使用它了,但据我了解,conda 就像 pip 的并行 package 管理器,但对于 Z7DAD1C2A46C5298F3E2C95D3BABF8D0CZ4 设置。
How to check which Python interpreter Spyder is running on its console? 如何检查哪个 Python 解释器 Spyder 在其控制台上运行?
which references this, probably the direct solution you need:其中引用了这一点,可能是您需要的直接解决方案:
How to change python version in anaconda spyder 如何在 anaconda spyder 中更改 python 版本
Have you tried using the PYCharm IDE to install packages?您是否尝试过使用 PYCharm IDE 安装软件包?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.