7

我在win 7下的cygwin上使用virtualenv 1.9.1。每个virtualenv都是在没有任何选项的情况下创建的(显然,除了目录名称之外)。没有花哨的定制。

所有 virtualenvs 都是新鲜的,因为我没有创建任何包装脚本,也没有编辑任何 virtualenv 脚本。我完全确定我没有做任何特别的事情(即除了滥用 virtualenv,而不是采取阻碍其操作的行动)这导致 PYTHONPATH 在多个 virtualenvs 中不存在。

每个新 virtualenv 的 virtualenv 激活脚本不会创建 PYTHONPATH。pip 在$VIRTUAL_ENV/lib/python2.7/site-packages/<packagedir>(例如lib/python2.7/site-packages/html5lib)下安装软件包。

pip 的行为似乎是可取的。但是,运行 python(在激活 virtualenv 之后)会导致无法加载 pip 安装的包(即“没有名为...的模块”)。

更新:添加 PYTHONPATHactivate确实“解决”了这个问题。显然,我不想手动维护它,也不想更新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
4

2 回答 2

1

我在 Win7 上,运行 cygwin 的 Python。我已经用这个安装了easy_install 。然后是 pip,然后是 virtualenv。然后运行virtualenv newve,然后source newve/bin/activate,然后 pip 安装了一个包(IPython)。一切正常。我可以从 python REPL 导入,程序运行正常,路径设置正确。而且 PYTHONPATH 永远不会在任何地方设置。我不知所措。

尝试重新安装所有内容?

编辑:

发现 easy_install 在 cygwin 包中可用python-setuptools

于 2013-05-02T17:58:13.310 回答
0

我唯一能想到的是 PYTHONPATH 已经设置好了。由于 Cygwin 继承了 Windows 的所有环境变量,如果 PYTHONPATH 已经设置,virtualenv 将使用它而不是正确的目录。检查是否已经设置了 Windows 下的 PYTHONPATH。如果是,请将其删除并再次尝试 virtualenv。还要检查你的 .bashrc 文件,看看是否在那里设置了 PYTHONPATH。为什么不能在 Windows 上使用普通的 Python?您正在编写 POSIX 脚本吗?

于 2013-05-01T23:11:10.957 回答