1

I created a Python 3 virtualenv, like this:

mkproject -p python3 flowerid

But when I try to install anything with pip (inside this virtualenv) I get this error:

cd flowerid
pip install ipython
Traceback (most recent call last):
  File "/Users/nicolas/.virtualenvs/flowerid/bin/pip", line 11, in <module>
    load_entry_point('pip==9.0.1', 'console_scripts', 'pip')()
  File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pkg_resources/__init__.py", line 560, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2648, in load_entry_point
    return ep.load()
  File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2302, in load
    return self.resolve()
  File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2308, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pip/__init__.py", line 28, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pip/vcs/subversion.py", line 9, in <module>
    from pip.index import Link
  File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pip/index.py", line 31, in <module>
    from pip.wheel import Wheel, wheel_ext
  File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pip/wheel.py", line 6, in <module>
    import compileall
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/compileall.py", line 20, in <module>
    from concurrent.futures import ProcessPoolExecutor
  File "/Library/Python/2.7/site-packages/concurrent/futures/__init__.py", line 8, in <module>
    from concurrent.futures._base import (FIRST_COMPLETED,
  File "/Library/Python/2.7/site-packages/concurrent/futures/_base.py", line 357
    raise type(self._exception), self._exception, self._traceback
                               ^
SyntaxError: invalid syntax

Everything looks normal until the 'futures' import that goes to "/Library/Python/2.7".

I tried to set "--no-site-packages" when creating the virtualenv, but that doesn't change anything (and it shouldn't as it's the default).

I tried to use pip3 instead, same thing.

I tried to reinstall pip (in the virtualenv) with easy_install pip, same thing...

Any other ideas? Thanks for your help.

Note: I usually use Python 2.7 - I do have many Python 2.7 packages installed globally - perhaps that's what create the conflicts?

I'm on OSX El Capitan.

Update: My virtualenv seems activated - it starts off using the pip and python from my virtualenv. And 'which python' uses python from the virtualenv.

(flowerid) nicolas@~/venv_projects/flowerid$ which python
/Users/nicolas/.virtualenvs/flowerid/bin/python 
Tickon
  • 1,058
  • 1
  • 16
  • 25

3 Answers3

1

Ok, I figured it out. It was my environmental variable PYTHONPATH - that was messing things up - telling Python to look in the Python 2.7 libraries... I am setting up my PYTHONPATH in my .bashrc.

So the solution is to change the PYTHONPATH on activation and setting back the previous setting on deactivation (it boggles my mind a bit that this is not default...)

So in /Users/nicolas/.virtualenvs/flowerid/bin/activate add:

# Fix PYTHONPATH imports
export OLD_PYTHONPATH="$PYTHONPATH"
export PYTHONPATH="/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/"

And in /Users/nicolas/.virtualenvs/flowerid/bin/postdeactivate:

# Reset PYTHONPATH to previous state
export PYTHONPATH="$OLD_PYTHONPATH"

Here's where I found out what the problem was: virtualenv --no-site-packages and pip still finding global packages?

And the solution: How do you set your pythonpath in an already-created virtualenv?

Tickon
  • 1,058
  • 1
  • 16
  • 25
-1

Try replacing the line in /Library/Python/2.7/site-packages/concurrent/futures/_base.py

    raise type(self._exception), self._exception, self._traceback

with this

    raise Exception(self._exception), self._exception, self._traceback
-1

Try using pip3 instead of pip command. Since you are using python 3.

MDK
  • 1
  • 3
  • I tried that, same thing. It starts up using Python3, then for some reason switch to Python 2.7 when importing futures. – Tickon May 29 '17 at 11:52
  • Did you try running this, examples from python docs: `python3 -m pip install SomePackage` – MDK May 29 '17 at 12:44