6

My system is running CentOS 6. I do not have admin access, so sudo is not available. I have Python 2.7.3 available, along with pip and virtualenv. I was hoping that I could use these to set up a new virtual environment in which to install & run Python 3.5 or above.

I tried the method described here: Using Python 3 in virtualenv

But got this error:

$ virtualenv -p python3 venv
The path python3 (from --python=python3) does not exist

My system also has a Python 3.4 module installed, so I tried that, however virtualenv does not seem to work there:

$ module load python/3.4.3
$ virtualenv -p python3 venv
-bash: virtualenv: command not found

This appears to make sense since virtualenv is only installed for Python 2.7:

$ module unload python
$ module load python/2.7
$ which virtualenv
/local/apps/python/2.7.3/bin/virtualenv

So, the next logical step would seem to be installing virtualenv for my Python 3... but this does not work either:

$ pip3 install virtualenv
Traceback (most recent call last):
  File "/local/apps/python/3.4.3/bin/pip3", line 7, in <module>
    from pip import main
ImportError: cannot import name 'main'

also

$ pip3 install --user virtualenv
Traceback (most recent call last):
  File "/local/apps/python/3.4.3/bin/pip3", line 7, in <module>
    from pip import main
ImportError: cannot import name 'main'

I started Google'ing this new error message, but did not see anything that seemed relevant for this situation. Any ideas? Even if I could get virtualenv installed on my Python 3.4 module, would I still be unable to upgrade it to Python 3.5+?

To round things out, I also tried to compile my own Python 3.6 from source, but that does not work either:

Python-3.6.0$ make install
if test "no-framework" = "no-framework" ; then \
        /usr/bin/install -c python /usr/local/bin/python3.6m; \
    else \
        /usr/bin/install -c -s Mac/pythonw /usr/local/bin/python3.6m; \
    fi
/usr/bin/install: cannot create regular file `/usr/local/bin/python3.6m': Permission denied
make: *** [altbininstall] Error 1

more background info:

$ which pip3
/local/apps/python/3.4.3/bin/pip3

$ which python
/local/apps/python/3.4.3/bin/python
Community
  • 1
  • 1
user5359531
  • 3,217
  • 6
  • 30
  • 55
  • to create a virtualenv for python3.5, you must have python3.5 installed on your OS; can you open python shell by `python3`? I think it should be `virtualenv python3.4 venv` when creating virtualenv based on python3.4 – Haifeng Zhang Feb 21 '17 at 20:40
  • Since I can't install Python 3.x from source, I am guessing that it will be impossible for me to install Python 3.5+ then? Running `virtualenv -p /local/apps/python/3.4.3/bin/python venv` does seem to create the virtual environment correctly, though its still not running Python 3.5+ as needed. – user5359531 Feb 21 '17 at 20:52

3 Answers3

8

You can download miniconda or Anaconda. It does not require superuser privileges because it installs in your home directory. After you install you can create new environments like this:

conda create -n py35 python=3.5

Then you can switch to the new environment:

source activate py35
Tom Lynch
  • 893
  • 6
  • 13
  • Looks like this works, after running `module unload python` on my system to clear out loaded Pythons, and then running `export PYTHONPATH=/home/user/anaconda3/bin:$PYTHONPATH; export PATH=/home/user/anaconda3/bin:$PATH ` to set the correct path variables – user5359531 Feb 21 '17 at 23:29
2

Try this for Windows.

virtualenv -p C:\Python35\python.exe django_concurrent_env
cd django_concurrent_env
.\Source\activate
deactivate
Umar Asghar
  • 3,808
  • 1
  • 36
  • 32
1

Try out the following commands:

pip3 install virtualenv
pip3 install virtualenvwrapper
mkdir ~/.virtualenvs
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
source ~/.bash_profile
which python3

Now copy the result of path of python3 in the last command and put it in the following command:

mkvirtualenv --python=python3/path/in/last/command myenv

I'm assuming pip3 is already installed. If not, install it before running these commands.

Source: https://docs.coala.io/en/latest/Help/MAC_Hints.html#create-virtual-environments-with-pyvenv

(I do have sudo access on my machine. I've not tried the commands without it. Please post if any issues comes.)

Since you already have virtualenv installed, you might only need to update the files and then run the command mkvirtualenv with proper arguments.

shreyans800755
  • 244
  • 1
  • 10