Creating a Virtual Environment

hemla21 at gmail.com hemla21 at gmail.com
Tue Jul 7 10:02:02 EDT 2015


Dear all, 

I have made a python program which I would like to be able to install on to linux machine. I want my python code to be able to use a standalone python with the libraries installed. 

The code works with python3.4 and above and uses h5py and numpy packages. 

I was looking at the options I had and understood that it is a good idea to use virtualenv. 

I followed the following steps:

1. I installed anaconda3 python in to my home directory. I prepended the path to PATH, so python now refers to the anaconda version. The reason I am trying to use anaconda3 is because it has all the packages I need already installed. 

source $HOME/anaconda3/bin/activate ~/anaconda3

2. Then I try to create a virtualenv by running the following command in the destination directory.
virtualenv -p /home/albert/anaconda3/bin/python3 --always-copy  .

This will give the following error:
Running virtualenv with interpreter /home/albert/anaconda3/bin/python3
Using base prefix '/home/albert/anaconda3'
New python executable in ./bin/python3
Traceback (most recent call last):
  File "/usr/lib/python3.3/site-packages/virtualenv.py", line 2308, in <module>
    main()
  File "/usr/lib/python3.3/site-packages/virtualenv.py", line 821, in main
    symlink=options.symlink)
  File "/usr/lib/python3.3/site-packages/virtualenv.py", line 956, in create_environment
    site_packages=site_packages, clear=clear, symlink=symlink))
  File "/usr/lib/python3.3/site-packages/virtualenv.py", line 1247, in install_python
    shutil.copyfile(executable, py_executable)
  File "/home/albert/anaconda3/lib/python3.4/shutil.py", line 109, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: './bin/python3'

If I run the same command using the administrator I get :
Using base prefix '/home/albert/anaconda3'
New python executable in ./bin/python3
Not overwriting existing python script ./bin/python (you must use ./bin/python3)
Traceback (most recent call last):
  File "/usr/lib/python3.3/site-packages/virtualenv.py", line 2308, in <module>
    main()
  File "/usr/lib/python3.3/site-packages/virtualenv.py", line 821, in main
    symlink=options.symlink)
  File "/usr/lib/python3.3/site-packages/virtualenv.py", line 956, in create_environment
    site_packages=site_packages, clear=clear, symlink=symlink))
  File "/usr/lib/python3.3/site-packages/virtualenv.py", line 1377, in install_python
    shutil.copyfile(py_executable_base, full_pth)
  File "/home/albert/anaconda3/lib/python3.4/shutil.py", line 108, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'python3'


I get exactly the same error, even if I use compile python from source ( not using anaconda version).

So my questions are:

1. Is virtualenv a good idea?
2. which python should I be using to create my virtualenv? System python? python compiled in user home directory? anaconda3?

I´d really appreciate your help. 
Thank you very much in Advance,



More information about the Python-list mailing list