我在win7下的cygwin上使用virtualenv 1.9.1。每個virtualenv都創建時沒有任何選項(顯然不是目錄名稱)。沒有華麗的定製。virtualenv不會創建PYTHONPATH/pip安裝的包不起作用
所有的virtualenvs都是新鮮的,因爲我沒有創建任何包裝腳本,也沒有編輯任何virtualenv腳本。我完全肯定我沒有做任何特別的事情(即,除了濫用virtualenv,而不是採取妨礙其操作的行動),這導致PYTHONPATH在多個虛擬世界中缺席。
對於每個新的virtualenv,virtualenv激活腳本不會創建PYTHONPATH。 pip在$VIRTUAL_ENV/lib/python2.7/site-packages/<packagedir>
下安裝軟件包(例如lib/python2.7/site-packages/html5lib
)。
pip的行爲似乎是可取的。 但是,運行python(激活virtualenv後)不會導致可裝載pip的軟件包(即「no module named ...」)。
更新:將一個PYTHONPATH添加到activate
確實「解決」了問題。顯然,我不想手動維護這個,也不必更新activate_this.py
。我仍然想知道爲什麼virtualenvs現在不能直接使用。
解決方案是什麼? virtualenv從來沒有用過這樣做。現在有什麼問題?
更新2:這裏是-vv運行的virtualenv的輸出:
$ virtualenv -vv newvirtualenv
Creating newvirtualenv/lib/python2.7
Symlinking Python bootstrap modules
Symlinking newvirtualenv/lib/python2.7/config
Symlinking newvirtualenv/lib/python2.7/lib-dynload
Symlinking newvirtualenv/lib/python2.7/os.py
Ignoring built-in bootstrap module: posix
Symlinking newvirtualenv/lib/python2.7/posixpath.py
Cannot import bootstrap module: nt
Symlinking newvirtualenv/lib/python2.7/ntpath.py
Symlinking newvirtualenv/lib/python2.7/genericpath.py
Symlinking newvirtualenv/lib/python2.7/fnmatch.py
Symlinking newvirtualenv/lib/python2.7/locale.py
Symlinking newvirtualenv/lib/python2.7/encodings
Symlinking newvirtualenv/lib/python2.7/codecs.py
Symlinking newvirtualenv/lib/python2.7/stat.py
Symlinking newvirtualenv/lib/python2.7/UserDict.py
File newvirtualenv/lib/python2.7/lib-dynload/readline.dll already exists
Symlinking newvirtualenv/lib/python2.7/copy_reg.py
Symlinking newvirtualenv/lib/python2.7/types.py
Symlinking newvirtualenv/lib/python2.7/re.py
Symlinking newvirtualenv/lib/python2.7/sre.py
Symlinking newvirtualenv/lib/python2.7/sre_parse.py
Symlinking newvirtualenv/lib/python2.7/sre_constants.py
Symlinking newvirtualenv/lib/python2.7/sre_compile.py
File newvirtualenv/lib/python2.7/lib-dynload/zlib.dll already exists
Symlinking newvirtualenv/lib/python2.7/warnings.py
Symlinking newvirtualenv/lib/python2.7/linecache.py
Symlinking newvirtualenv/lib/python2.7/_abcoll.py
Symlinking newvirtualenv/lib/python2.7/abc.py
Symlinking newvirtualenv/lib/python2.7/_weakrefset.py
Creating newvirtualenv/lib/python2.7/site-packages
Writing newvirtualenv/lib/python2.7/site.py
Writing newvirtualenv/lib/python2.7/orig-prefix.txt
Writing newvirtualenv/lib/python2.7/no-global-site-packages.txt
Creating parent directories for newvirtualenv/include
Symlinking newvirtualenv/include/python2.7
Creating newvirtualenv/bin
New python executable in newvirtualenv/bin/python2.7
Changed mode of newvirtualenv/bin/python2.7 to 0755
Also creating executable in newvirtualenv/bin/python
Changed mode of newvirtualenv/bin/python to 0755
Testing executable with newvirtualenv/bin/python2.7 -c "import sys;out=sys.stdout;getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))"
Got sys.prefix result: u'/cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv'
Creating newvirtualenv/lib/python2.7/distutils
Writing newvirtualenv/lib/python2.7/distutils/__init__.py
Writing newvirtualenv/lib/python2.7/distutils/distutils.cfg
Using existing setuptools egg: /usr/lib/python2.7/site-packages/virtualenv_support/setuptools-0.6c11-py2.7.egg
Installing setuptools...
Running command /cygdrive/c/Users/ma...ualenv/bin/python2.7 -c "#!python
\"\"\"Bootstra...sys.argv[1:])
" -v /usr/lib/python2.7/s...ols-0.6c11-py2.7.egg
Processing setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to /cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv/lib/python2.7/site-packages
Adding setuptools 0.6c11 to easy-install.pth file
Saving /cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv/lib/python2.7/site-packages/easy-install.pth
Installing easy_install script to /cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv/bin
changing mode of /cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv/bin/easy_install to 755
Installing easy_install-2.7 script to /cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv/bin
changing mode of /cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv/bin/easy_install-2.7 to 755
Installed /cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11
...Installing setuptools...done.
Installing existing pip-1.3.1.tar.gz distribution: /usr/lib/python2.7/site-packages/virtualenv_support/pip-1.3.1.tar.gz
Installing pip...
Running command /cygdrive/c/Users/ma...ualenv/bin/python2.7 -x /cygdrive/c/Users/ma...env/bin/easy_install /usr/lib/python2.7/s...ort/pip-1.3.1.tar.gz
Processing pip-1.3.1.tar.gz
Running pip-1.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ZP_VIv/pip-1.3.1/egg-dist-tmp-H3XBh_
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.txt' found under directory 'docs/_build'
no previously-included directories found matching 'docs/_build/_sources'
Adding pip 1.3.1 to easy-install.pth file
Installing pip script to /cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv/bin
Installing pip-2.7 script to /cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv/bin
Installed /cygdrive/c/Users/marcin/Documents/codeprojects/newvirtualenv/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg
Processing dependencies for pip==1.3.1
Finished processing dependencies for pip==1.3.1
...Installing pip...done.
Writing newvirtualenv/bin/activate
Writing newvirtualenv/bin/activate.fish
Writing newvirtualenv/bin/activate_this.py
Writing newvirtualenv/bin/activate.csh
醜陋的解決方案:可能破解'activate'腳本並手動添加路徑? – 2013-04-29 19:32:11
@JakubM。這發生在我身上,但是這似乎是我沒有做其他明顯的事情,或者是當前版本的virtualenv中的錯誤。 – Marcin 2013-04-29 19:33:40
'PYTHONPATH'是一個紅色的鯡魚。它不是由'activate'設置的**。它從來沒有。 'bin/python.exe'中的python可執行文件負責設置'PYTHONHOME'(內部)。你可以運行'virtualenv -vv'(所以有兩個'-v'選項)並在你的問題中向我們顯示這個調試輸出來幫助我們調試問題? – 2013-05-02 09:27:33