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
2
  • 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 Commented Feb 21, 2017 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. Commented Feb 21, 2017 at 20:52

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

1 Comment

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
2

Try this for Windows.

virtualenv -p C:\Python35\python.exe django_concurrent_env
cd django_concurrent_env
.\Source\activate
deactivate

Comments

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.

1 Comment

I updated the OP with the results of pip3 install commands (same error message), and also which python3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.