1

I updated the versions of mkvirtualenv and virtualenv

$ sudo pip install --upgrade virtualenv virtualenvwrapper

because my whole life I only used Python 2, and wanted to use -now- Python 3. The virtualenvwrapper had some issues.

Then I tried creating a virtual environment for my python3 installation:

$ mkvirtualenv py3test -p /usr/bin/python3

The environment is created in ~/.virtualenvs/py3test. Once active, I want to install a package I made:

(py3test)$ pip install python-cantrips (py3test)$ pip freeze

And the package is appropriately installed. Then I install ipython and run it:

(py3test)$ pip install ipython (py3test)$ ipython

And I enter ipython appropriately. But then I...

import cantrips

And it explodes with an ImportError. Then I check sys.path. And the issue is here: sys.path includes a path like: '/home/myuser/.virtualenvs/py3test/lib/python2.7/site-packages'. I don't remember whether the path is exact or not, since I am not in such computer right now. But I can have one thing for sure: the environment was created with python3 (the directory is not python2.7 but python3.5 in my virtualenv).

So: Why is virtualenv creating an environment for python3 but adding me the paths as if it was a python2.7 environment instead?

3
  • 1
    Are you tried to use pip3? If you wanna have env for Python3 run this python3 -m venv ENV Commented Sep 6, 2017 at 20:41
  • 1
    When you just run python which version is shown? Commented Sep 6, 2017 at 21:11
  • @KlausD. The default python version I use, is Python 2.7. Should I change the default python option before running mkvirtualenv? What's the purpose of the -p option in virtualenv if so? Commented Sep 7, 2017 at 16:00

1 Answer 1

2

Found it!

There was no issue with virtualenv or virtualenvwrapper. The issue was with ipython. Actually, there is no issue specifically with ipython but with the way the scripts are accessible inside a virtualenv.

Globally, I had ipython installed (which works with the global python27). When I installed ipython in my local python3 environment, the (shell) path was not updated until I somehow refresh the environment again (e.g. deactivating, activating again). So when I tried again, the ipython was the appropriate (the local ipython in my environment with 3.5), and the generated path was the expected one.

Sign up to request clarification or add additional context in comments.

Comments

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.