Many Problems with python's virtualenv

2019-08-06 00:35发布

I've been having a lot of trouble with getting virtualenv to work.

First I installed it via pip and then tried setting up a virtualenv. That didn't work and I got this error message:

    ResNets-iMac:desktop zachary$ virtualenv anothertest
Using base prefix '/Applications/Canopy.app/appdata/canopy-1.5.1.2730.macosx-x86_64/Canopy.app/Contents'
New python executable in anothertest/bin/python
dyld: Library not loaded: @rpath/Python
  Referenced from: /Users/zachary/Desktop/anothertest/bin/python
  Reason: image not found
ERROR: The executable anothertest/bin/python is not functioning
ERROR: It thinks sys.prefix is u'/Users/zachary/Desktop' (should be u'/Users/zachary/Desktop/anothertest')
ERROR: virtualenv is not compatible with this system or executable

So then I went through just about all of the troubleshooting I could and decided that Canopy was the problem. So I deleted that, reinstalled virualenv (via 'pip uninstall virtualenv' then 'pip install virtualenv') and now I am getting this error whenever I try to do anything involving virtualenv:

dyld: Library not loaded: @rpath/Python
  Referenced from: /Users/zachary/Library/Enthought/Canopy_64bit/User/bin/python
  Reason: image not found

I'm not sure what to do and when I check what my default version of python is, I get:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

I very new at all of this and I don't really have any idea what I have been doing or how to fix this so any help would be greatly appreciated.

Thanks!

2条回答
家丑人穷心不美
2楼-- · 2019-08-06 00:51

The Enthought Canopy website recommends this: to use venv, and not virtualenv.

查看更多
太酷不给撩
3楼-- · 2019-08-06 01:06

The problem is you have multiple versions of Python on your system.

You have the Python that ships with OSX (/Library/Frameworks/Python.framework/Versions/2.7/bin/python), then you have the Python that comes with Canopy; which is /Users/zachary/Library/Enthought/Canopy_64bit/User/bin/python.

Your path is pointing the default version to the one from Canopy, yet pip is installed against the default system version of Python.

So when you installed virtualenv, it was installed against the default version of Python; but when you try to create a virtual environment - due to the way your path are setup, it is trying to use the Canopy version of Python - and that's the source of your error.

To solve this problem you can do any of the following:

  1. Remove Canopy, and use the OSX version of Python.
  2. Install virtualenv on the Canopy version of Python.
  3. Modify your PATH so that the system version of Python takes precedence.
  4. Install another version of Python (from say, homebrew) and make that the default.

The resolution you chose will depend on what you need the system to do. If you need the libraries bundled with Canopy, then you need to choose option #2, otherwise pick any of the other options. #4 is the most disruptive (as it will involve installing a lot of other stuff).

查看更多
登录 后发表回答