Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

python - Problem Setting Up A Virtualenv

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...