设置 Virtualenv 时出现问题

发布于 2024-11-05 09:37:26 字数 3890 浏览 3 评论 0原文

我正在尝试使用 Python 2.6.5 在 Ubuntu 10.04 上设置 virtualenv,但遇到一些问题。

使用 pip 安装 virtualenv 和 virtualenv 包装器后,我运行命令: virtualenv mysite-env --verbose

我收到以下错误:

Creating mysite-env/lib/python2.6
Symlinking Python bootstrap modules
  Symlinking mysite-env/lib/python2.6/lib-dynload
  Symlinking mysite-env/lib/python2.6/config
  Symlinking mysite-env/lib/python2.6/os.py
  Ignoring built-in bootstrap module: posix
  Symlinking mysite-env/lib/python2.6/posixpath.py
  Cannot import bootstrap module: nt
  Symlinking mysite-env/lib/python2.6/ntpath.py
  Symlinking mysite-env/lib/python2.6/genericpath.py
  Symlinking mysite-env/lib/python2.6/fnmatch.py
  Symlinking mysite-env/lib/python2.6/locale.py
  Symlinking mysite-env/lib/python2.6/encodings
  Symlinking mysite-env/lib/python2.6/codecs.py
  Symlinking mysite-env/lib/python2.6/stat.py
  Symlinking mysite-env/lib/python2.6/UserDict.py
  Symlinking mysite-env/lib/python2.6/lib-dynload/readline.so
  Symlinking failed, copying to mysite-env/lib/python2.6/lib-dynload/readline.so
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 9, in <module>
    load_entry_point('virtualenv==1.6.1', 'console_scripts', 'virtualenv')()
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 795, in main
    never_download=options.never_download)
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 886, in create_environment
    site_packages=site_packages, clear=clear))
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1020, in install_python
    copy_required_modules(home_dir)
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 974, in copy_required_modules
    copyfile(filename, dst_filename)
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 414, in copyfile
    copyfileordir(src, dest)
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 391, in copyfileordir
    shutil.copy2(src, dest)
  File "/usr/lib/python2.6/shutil.py", line 99, in copy2
    copyfile(src, dst)
  File "/usr/lib/python2.6/shutil.py", line 53, in copyfile
    fdst = open(dst, 'wb')
IOError: [Errno 20] Not a directory: 'mysite-env/lib/python2.6/lib-dynload/readline.so'

如果再次运行它,我收到以下错误:

Directory mysite-env/lib/python2.6 already exists
    Symlinking Python bootstrap modules
      Ignoring built-in bootstrap module: posix
      Cannot import bootstrap module: nt
      Symlinking mysite-env/lib/python2.6/lib-dynload/readline.so
      Symlinking mysite-env/lib/python2.6/copy_reg.py
      Symlinking mysite-env/lib/python2.6/types.py
      Symlinking mysite-env/lib/python2.6/re.py
      Symlinking mysite-env/lib/python2.6/sre.py
      Symlinking mysite-env/lib/python2.6/sre_parse.py
      Symlinking mysite-env/lib/python2.6/sre_constants.py
      Symlinking mysite-env/lib/python2.6/sre_compile.py
      Ignoring built-in bootstrap module: zlib
      Symlinking mysite-env/lib/python2.6/warnings.py
      Symlinking mysite-env/lib/python2.6/linecache.py
      Symlinking mysite-env/lib/python2.6/_abcoll.py
      Symlinking mysite-env/lib/python2.6/abc.py
    Creating mysite-env/lib/python2.6/site-packages
    Writing mysite-env/lib/python2.6/site.py
    Writing mysite-env/lib/python2.6/orig-prefix.txt
    Creating parent directories for mysite-env/include
    Symlinking mysite-env/include/python2.6
    Creating mysite-env/bin
    New python executable in mysite-env/bin/python
    Changed mode of mysite-env/bin/python to 0755
    Testing executable with mysite-env/bin/python -c "import sys; print(sys.prefix)"
    ERROR: The executable mysite-env/bin/python is not functioning
    ERROR: It thinks sys.prefix is u'/usr' (should be '/vagrant/mysite-env')
    ERROR: virtualenv is not compatible with this system or executable

有什么想法如何解决此问题吗?谢谢!

I'm trying to set up a virtualenv on Ubuntu 10.04 with Python 2.6.5 but having some issues.

After having installed virtualenv and virtualenv wrapper with pip, I'm running the command: virtualenv mysite-env --verbose

I get the following error:

Creating mysite-env/lib/python2.6
Symlinking Python bootstrap modules
  Symlinking mysite-env/lib/python2.6/lib-dynload
  Symlinking mysite-env/lib/python2.6/config
  Symlinking mysite-env/lib/python2.6/os.py
  Ignoring built-in bootstrap module: posix
  Symlinking mysite-env/lib/python2.6/posixpath.py
  Cannot import bootstrap module: nt
  Symlinking mysite-env/lib/python2.6/ntpath.py
  Symlinking mysite-env/lib/python2.6/genericpath.py
  Symlinking mysite-env/lib/python2.6/fnmatch.py
  Symlinking mysite-env/lib/python2.6/locale.py
  Symlinking mysite-env/lib/python2.6/encodings
  Symlinking mysite-env/lib/python2.6/codecs.py
  Symlinking mysite-env/lib/python2.6/stat.py
  Symlinking mysite-env/lib/python2.6/UserDict.py
  Symlinking mysite-env/lib/python2.6/lib-dynload/readline.so
  Symlinking failed, copying to mysite-env/lib/python2.6/lib-dynload/readline.so
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 9, in <module>
    load_entry_point('virtualenv==1.6.1', 'console_scripts', 'virtualenv')()
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 795, in main
    never_download=options.never_download)
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 886, in create_environment
    site_packages=site_packages, clear=clear))
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1020, in install_python
    copy_required_modules(home_dir)
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 974, in copy_required_modules
    copyfile(filename, dst_filename)
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 414, in copyfile
    copyfileordir(src, dest)
  File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 391, in copyfileordir
    shutil.copy2(src, dest)
  File "/usr/lib/python2.6/shutil.py", line 99, in copy2
    copyfile(src, dst)
  File "/usr/lib/python2.6/shutil.py", line 53, in copyfile
    fdst = open(dst, 'wb')
IOError: [Errno 20] Not a directory: 'mysite-env/lib/python2.6/lib-dynload/readline.so'

If I run it again, I get the following:

Directory mysite-env/lib/python2.6 already exists
    Symlinking Python bootstrap modules
      Ignoring built-in bootstrap module: posix
      Cannot import bootstrap module: nt
      Symlinking mysite-env/lib/python2.6/lib-dynload/readline.so
      Symlinking mysite-env/lib/python2.6/copy_reg.py
      Symlinking mysite-env/lib/python2.6/types.py
      Symlinking mysite-env/lib/python2.6/re.py
      Symlinking mysite-env/lib/python2.6/sre.py
      Symlinking mysite-env/lib/python2.6/sre_parse.py
      Symlinking mysite-env/lib/python2.6/sre_constants.py
      Symlinking mysite-env/lib/python2.6/sre_compile.py
      Ignoring built-in bootstrap module: zlib
      Symlinking mysite-env/lib/python2.6/warnings.py
      Symlinking mysite-env/lib/python2.6/linecache.py
      Symlinking mysite-env/lib/python2.6/_abcoll.py
      Symlinking mysite-env/lib/python2.6/abc.py
    Creating mysite-env/lib/python2.6/site-packages
    Writing mysite-env/lib/python2.6/site.py
    Writing mysite-env/lib/python2.6/orig-prefix.txt
    Creating parent directories for mysite-env/include
    Symlinking mysite-env/include/python2.6
    Creating mysite-env/bin
    New python executable in mysite-env/bin/python
    Changed mode of mysite-env/bin/python to 0755
    Testing executable with mysite-env/bin/python -c "import sys; print(sys.prefix)"
    ERROR: The executable mysite-env/bin/python is not functioning
    ERROR: It thinks sys.prefix is u'/usr' (should be '/vagrant/mysite-env')
    ERROR: virtualenv is not compatible with this system or executable

Any ideas how to fix this? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

余生共白头 2024-11-12 09:37:26

自从你问这个问题以来,似乎已经有点过了。 Virtualbox 的 /vagrant 目录的文件驱动程序无法识别 virtualenv 经常使用的符号链接。

这可以通过一个简单的更新得到最好的证明

mybox:/vagrant$ ln -s ~/.bashrc
ln: failed to create symbolic link ./.bashrc': Protocol error`

因为 vagrant 与符号链接和符号链接不兼容。 virtualenv,我的 vagrant 盒子/实例是特定于任务/项目的(只有 1 个 virtualenv)。因此,在 vagrant 主机端/实例文件夹中,我会保留一个简短的脚本来安装 python 和virtualenv,然后做

pip install -r /vagrant/requirement

更多文档可以在这里找到。 https://docs.vagrantup.com/v2/provisioning/basic_usage.html

通过适当的 bash if 检查(python 是否存在,/home/vagrant/env 是否存在),您可以配置一次盒子,然后附加一个调用来激活您的 ~/env 安装,以便当您登录,您已经设置完毕并准备就绪。

Seems like its been a bit since you asked this. Virtualbox's file driver for the /vagrant directory cannot recognize symbolic links which virtualenv uses a lot.

This can be best demonstrated with a simple

mybox:/vagrant$ ln -s ~/.bashrc
ln: failed to create symbolic link ./.bashrc': Protocol error`

Update:

Because of vagrant's incompatibility with symbolic links & virtualenv, my vagrant boxes/instances were task/project specific ( only 1 virtualenv). So in the vagrant host side/instance folder I would keep a short script to install python & virtualenv, then do

pip install -r /vagrant/requirement

Further documentation can be found here. https://docs.vagrantup.com/v2/provisioning/basic_usage.html

with the appropriate bash if checks ( does python exist, does /home/vagrant/env exist ), you can provision your box once and then append a call to activate your ~/env install so that when you login, your already setup and ready to go.

叫思念不要吵 2024-11-12 09:37:26

发生此错误是因为您正在使用的 virtualenv.py 文件与您正在使用的 python 版本不兼容。
对于 python2.7,您需要从 virtualenv.org 站点下载二进制文件,然后

python setup.py install

在安装后使用已安装的二进制文件(不是 virtualenv.py 文件)来编译它们来创建虚拟环境

virtualenv --no-site-packages <path to virtual env directory>/env/

This error occurs because the virtualenv.py file you are using is not compatible with the python version that you are using..
For python2.7 you need to downalod the binaries from the virtualenv.org site and then compile them using

python setup.py install

after the installation use the installed binary(not the virtualenv.py file) to create virtual environment by

virtualenv --no-site-packages <path to virtual env directory>/env/
满地尘埃落定 2024-11-12 09:37:26

这个问题已经有几个答案,但我想分享我的解决方案,以防它对下一个人有所帮助。

我在哪里运行命令很重要。我在 /vagrant 共享文件夹中运行 virtualenv env 命令。那是我的错误。当我 cd 返回到我的 HOME 目录,然后运行 ​​virtualenv env 时,一切正常。

This issue already has several answers, but I want to share my solution, in case it helps the next person.

Where I run the command matters. I was running the virtualenv env command inside the /vagrant shared folder. That was my mistake. When I cd back to my HOME dir, then run virtualenv env, everything works fine.

清泪尽 2024-11-12 09:37:26

我还没有遇到这个特殊问题,但我个人已经从使用 virtualenv 切换到 pythonbrewpythonbrew 是同一问题的不同解决方案;它的工作方式更像是 Ruby 社区中的 rvm:它构建完全独立的版本Python,从头开始,位于 $HOME/.pythonbrew 下;然后,它提供了 shell 功能,使您可以轻松地从一个外壳切换到另一个外壳(为您编辑路径等)。它不像 virtualenv 那样轻量级,但它也不依赖于 Python 系统,因此整个符号链接问题就消失了。您还可以安装多个 Python 版本,即使它们未安装在基本系统中。

当然,您的情况可能会有所不同,但 pythonbrew 对我来说一直运行良好。

I haven't run across this particular problem, but I've personally switched from using virtualenv to pythonbrew. pythonbrew is a different solution to the same problem; it works more like rvm in the Ruby community: It builds entirely self-contained versions of Python, from scratch, under $HOME/.pythonbrew; then, it provides shell functions that allow you to switch easily from one to another (editing the path for you, etc.). It's not as lightweight as virtualenv, but it also doesn't piggyback on the system Python, so the whole symlink issue goes away. You can also install multiple Python versions, even if they're not installed in the base system.

Your mileage may vary, of course, but pythonbrew has been working well for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文