I’ll preface this by admitted that I may not totally understand the inner-workings of Virtual Environments, so please forgive me if I’ve committed an utter fail.
For my Desktop (Mac OS X 10.7 + Python 2.7) I have a Virtual Environment that houses a web application I’m building in Python (using Flask as the framework). I wanted to do some work on laptop, so I zipped up the directory that contained the virtual environment and my code and transfered it over to my laptop (Mac OS X 10.7 + Python 2.7).
After unzipping, I tried to launch my application and received the following message:
(venv)****:*** ***$ python runserver.py
Traceback (most recent call last):
File "runserver.py", line 2, in <module>
from weirdcanada import app
File "/Users/****/****/weirdcanada/weirdcanada/__init__.py", line 3, in <module>
import weirdcanada.views
File "/Users/****/****/weirdcanada/weirdcanada/views.py", line 18, in <module>
from flaskext.principal import AnonymousIdentity
ImportError: No module named flaskext.principal
I then tried pip install flask-principal and after installing it, I re-ran the application and received the same error. I checked the site-packages in the virtual environment and flask-principal is installed.
My questions:
- Am I misunderstanding the point of Virtual Environments? Should I be able to copy a Virtual Environment over like I have? I thought consistency and portability were the main features.
- How can I fix this?
Thanks for your help!
I am pretty sure that changing this line:
to
should work.
I have 3 virtual environments installed on my system(Mac OSX 10.6 + Python2.7). I created a new virtualenv and suddenly the code which is working fine in other virtualenv is not working here and in that case flaskext.wtf was the culprit.
I checked versions of flask and its extensions in both the virtualenvs and they were exactly same so version problem was also out of question.
It does not make sense why this should happen but anyways try this and reply back.