0

I recently upgraded to OSX Sierra, and now I can't import any packages in Python. When I run a standard import numpy in the python console (I'm using Pycharm) I get

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. I'm pretty sure everything was working in python after I'd upgraded to Sierra, but broke once I did this.

My first thought was to reinstall numpy, but when I go to the command line and run pip install numpy, I get

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. Since it might be relevant, which python gives me /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.

Community
  • 1
  • 1
macinblack
  • 19
  • 6
  • First thing to rule out: have you tried doing import in python outside of PyCharm? second thing is to check `sys.path` which should contain `/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python` or at least something directly related to it. – Tadhg McDonald-Jensen Dec 16 '16 at 19:28
  • 1
    `which numpy` won't work because numpy isn't an executable to the OS, so it won't know what it's looking for. – wpercy Dec 16 '16 at 19:29
  • I did try importing numpy by entering `python` on the command line, and then importing from there. It didn't throw any errors, but it didn't appear to be working in the console either once I went back to check. On the other hand, pretty much all of my paths are some variation of `'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.14-py2.7.egg'`. As in, they all start with `/opt/local` rather than `/System`. Could that be the issue? – macinblack Dec 16 '16 at 22:49

2 Answers2

1

In my PyCharm I use virtual environments. An upgrade to Sierra may have, as you suggested, removed the Python port and thus your virtual environment may need to be recreated too.

Barc
  • 23
  • 1
  • 4
  • I don't think I've been using any virtual environments; I definitely haven't knowingly created one. Is there a possibility that my Pycharm was using one by default and I didn't know? – macinblack Dec 16 '16 at 23:28
  • @macinblack No, it doesn't, but you should. – Ramon Melo Jan 19 '17 at 01:31
0

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). 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.

macinblack
  • 19
  • 6
  • If you set up a virtual environment, you don't need to specify your python version. Go to Settings > Project > Project Interpreter > click on the gear icon > Create VirtualEnv. – Ramon Melo Jan 19 '17 at 01:30
  • Now that I have everything running smoothly under python 3.3, is there a reason to be using a virtualenv? What are the advantages for current/future projects? – macinblack Jan 20 '17 at 17:25
  • Virtualenvs allow you to update and upgrade your global environment (including python version) without affecting your project's environment. It also keeps your list of requirements tidy, should you need to move your app or install it somewhere else. I can't list advantages for your current project, since I don't know anything about its current state. However, for future projects, it would avoid issues like this one, since OS updates don't affect virtual environments. – Ramon Melo Jan 20 '17 at 17:34