13

Things were working fine a moment ago. I have no idea what I did to piss off virtualenv, but it's acting very strangely now. Any help is appreciated.

When making a virtualenv, I use this command:

virtualenv -p /usr/bin/python3 venv

Now I see that the packages I install using pip install package are not being loaded by python. They are installed correctly by pip, into the venv/lib/python3.4/site-packages directory, however the python in my virtualenv is not looking through that directory for packages.

in Python:

import sys
sys.path
['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']

This is wrong! It's using the wrong paths, and it should at least include

/myhomedir/venv/lib/python3.4/site-packages

So I can import my packages.

In fact, in Python opened in a virtualenv:

import sys
sys.path.append("/myhomedir/venv/lib/python3.4/site-packages")
import package

works!!

But I don't want to have to manually append this path every time I use Python. I did something to make sys.path very angry, and I don't know what that is.

I just sudo apt-get updated and sudo apt-get upgraded to make sure it wasn't a conflict... no dice.

Possibly related:

I've noticed that my virtualenv command outputs the following line:

Using base prefix '/usr'

I don't recall this happening before. However even when I do virtualenv venv, (without specifying Python version, and that output does not appear) my sys.path is still wrong and packages don't load.

Anyone thoughts? Help is greatly appreciated.

asked Apr 9, 2015 at 2:56

1 Answer 1

22

Solved the problem... posting result if anyone else has the same issue. A PICNIC error of the highest degree.

In my .bashrc file, I had an alias python=/usr/bin/python3

Well when my virtualenv tried to execute python, it was re-routing to /usr/bin instead of using it's internal python.

answered Apr 14, 2015 at 5:35
Sign up to request clarification or add additional context in comments.

5 Comments

Two days of searching and Q&A to solve this. Thank you!
Is there anyway to make the environment uses internal Python without having to export the python path every time?
@LongLe Yes, just add "alias python=python3 " and "alias pip=pip3" to your ~/.bashrc and create a symbolic link from /usr/bin/python to /usr/bin/python3 "sudo ln -sfn /usr/bin/python3 /usr/bin/python"
I have the same issue, but my ~/.bashrc doesn't have that alias, so I can't remove it.. My virtualenv is using /usr/bin/python3
you can check if you python has been aliased somewhere by alias | grep python and then remove that alias by unalias python

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.