开发者

virtualenv command not found after installed with MacPorts

开发者 https://www.devze.com 2023-03-17 23:30 出处:网络
I have python 2.7 installed via mac ports on a mac. I installed virtualenv via macports (py27-virtualenv @1.6.1_0 (active). When issue the command: virtualenv demo_venv --no-site-packages, I get this

I have python 2.7 installed via mac ports on a mac. I installed virtualenv via macports (py27-virtualenv @1.6.1_0 (active). When issue the command: virtualenv demo_venv --no-site-packages, I get this error: -bash: virtualenv:command no开发者_运维技巧t found. It's not picking virtualenv up @ all, so do I need to symlink it to my python27 location?


As you noted, MacPorts offers several versions of pyXX-virtualenv packages. You need to tell MacPorts which of those versions you want to use by default:

port select --list virtualenv
port select --set virtualenv virtualenv27
which virtualenv

After this, you should be able to just type virtualenv (assuming the MacPorts bin directory is in your path).


The command is virtualenv-2.7, not just virtualenv.

If you look at the package contents, you can see that no executable named virtualenv is installed.


MacPorts installs versioned links to virtualenv in /opt/local/bin, the default location for MacPorts. When using MacPorts, you need to ensure /opt/local/bin is on your shell PATH environment variable. Here, I show both py26-virtualenv and py27-virtualenv installed:

$ echo $PATH
/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Developer/Tools
$ ls -l /opt/local/bin/virtuale*
lrwxr-x---  1 root  admin  13 Oct 15  2009 /opt/local/bin/virtualenv@ -> virtualenv2.6
lrwxr-xr-x  1 root  wheel  74 May 17 02:20 /opt/local/bin/virtualenv-2.6@ -> /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/virtualenv
lrwxr-xr-x  1 root  wheel  74 May 17 02:29 /opt/local/bin/virtualenv-2.7@ -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
lrwxr-xr-x  1 root  wheel  88 Jun 27  2010 /opt/local/bin/virtualenvwrapper_bashrc-2.6@ -> /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/virtualenvw

In general, if you want to know what files a MacPort port installs and where, use port contents to find out:

$ port contents py27-virtualenv
Port py27-virtualenv contains:
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/PKG-INFO
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/SOURCES.txt
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/dependency_links.txt
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/entry_points.txt
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/not-zip-safe
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/top_level.txt
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.pyc
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv_support/__init__.py
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv_support/__init__.pyc
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv_support/distribute-0.6.16.tar.gz
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv_support/pip-1.0.1.tar.gz
  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv_support/setuptools-0.6c11-py2.7.egg
  /opt/local/bin/virtualenv-2.7
  /opt/local/share/doc/py27-virtualenv/index.txt
  /opt/local/share/doc/py27-virtualenv/news.txt


If you use virtualenvwrapper you can configure your shell environment to point to the correct virtualenv script. Install the py27-virtualenvwrapper port and add these lines to your Bash profile:

export VIRTUALENVWRAPPER_VIRTUALENV=/opt/local/bin/virtualenv-2.7
source /opt/local/bin/virtualenvwrapper.sh-2.7

No other path hackery or symlinks should be required when you use the virtualenvwrapper commands:

% mkvirtualenv demo_venv --no-site-packages


You need to make sure virtualenv is in your PATH, although it should be if it was installed correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消