简体   繁体   English

已安装Python模块,但不会导入

[英]Python modules installed, but won't import

I recently upgraded to OSX Sierra, and now I can't import any packages in Python. 我最近升级到了OSX Sierra,现在无法在Python中导入任何软件包。 When I run a standard import numpy in the python console (I'm using Pycharm) I get 当我在python控制台中运行标准import numpy时(我正在使用Pycharm),我得到了

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: No module named numpy

I think the problem's coming from when I reinstalled my ports when I was migrating macports, according to the instructions here . 根据此处的说明,我认为问题出在我迁移macport时重新安装端口时。 I'm pretty sure everything was working in python after I'd upgraded to Sierra, but broke once I did this. 我很确定升级到Sierra后,一切都可以在python中正常工作,但是一旦这样做,它就会崩溃。

My first thought was to reinstall numpy, but when I go to the command line and run pip install numpy , I get 我首先想到的是重新安装numpy,但是当我转到命令行并运行pip install numpy ,我得到了

Requirement already satisfied: numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python.

However, running which numpy turns up nothing, which seems weird, since it just told me that numpy's installed, and I can find it on my computer if I use easyfind. 但是,运行which numpy并不会产生任何效果,这似乎很奇怪,因为它只是告诉我已安装了numpy,如果使用easyfind,则可以在计算机上找到它。 Since it might be relevant, which python gives me /opt/local/bin/python . 由于可能相关, which python给了我/opt/local/bin/python

I've tried a few different fixes, but haven't been able to get anything to work so far. 我已经尝试了一些 不同的修复程序,但是到目前为止还无法使任何东西正常工作。 I have a feeling that I'm missing something very basic, but can't figure out what it is. 我感觉到我缺少一些非常基本的东西,但无法弄清楚它是什么。 I'm running python 2.7.12 on mac 10.12.1. 我在Mac 10.12.1。上运行python 2.7.12。

In my PyCharm I use virtual environments. 在我的PyCharm中,我使用虚拟环境。 An upgrade to Sierra may have, as you suggested, removed the Python port and thus your virtual environment may need to be recreated too. 如您建议的那样,升级到Sierra可能会删除Python端口,因此也可能需要重新创建虚拟环境。

Not exactly solving the original problem, but I did figure out how to work around it. 不能完全解决原始问题,但是我确实想出了解决方法。 I just installed python 3.3 (via macports) and set it to be the default python of my computer, and then reinstalled Pycharm (although I probably could have just restored settings to their defaults). 我刚刚安装了python 3.3(通过macports)并将其设置为计算机的默认python,然后重新安装了Pycharm(尽管我可能可以将设置恢复为默认值)。 Everything seems to be working now, in python 3.3, although I do have to use pip as python3.3 -m pip install rather than the standard pip install . 尽管我确实必须将pip用作python3.3 -m pip install而不是标准pip install ,但在python 3.3中一切似乎都可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM