简体   繁体   中英

linking python project with virtualenv

I have an ubuntu server 12 running as a guest in virtualbox on a windows 7 host. In a shared folder /workspace I have a python project project01. Since virtualbox has issues with creating symlinks in a shared folder I created the virtualenv in my users home directory. /home/user1/venv. I can activate the virtual environment no problem.

source ~/venv/bin/activate

but when I try to run manage.py, I get an error

~/venv/bin/python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named django.core.management

I'm sure I'm missing a path or something, but I'm not sure exactly what path to add and to where. I tried setting PYTHONPATH in the activate script, but that didn't work. Do I need to add the path to django's core management in the activate script? I see a bunch of django directories under venv/build

Django
django-appconf
django-celery
django-celery-email
django-celery-transactions
django-debug-toolbar
django-filebrowser
django-grappelli
djangohelpers
django-imagekit
django-pipeline
django-redis
django-sslify
django-storages
django-widget-tweaks

do I need to point in there somewhere? I'm very much a django and virtualenv noob.

UPDATE It doesn't look like the packages were installed. So this is another matter entirely. Thanks for your reply. I have some other issues I need to figure out here.

I was in the virtualenv and ran pip install -r requirements.txt which only had 1 error for postgres, but I'm not using a local postgres server so that's not a huge deal. Unless that error is preventing everything from installing, then it is a huge deal.

when I check site-packages I only see the following: easy-install.pth pip-1.2.1-py2.7.egg setuptools-0.6c11-py2.7.egg setuptools.pth

and pip freeze shows me: argparse==1.2.1 wsgiref==0.1.2

the error from pip install is: Exception information: Traceback (most recent call last): File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/basecommand.py", line 107, in main status = self.run(options, args) File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/commands/install.py", line 256, in run requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle) File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 1042, in prepare_files req_to_install.run_egg_info() File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 236, in run_egg_info command_desc='python setup.py egg_info') File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/util.py", line 612, in call_subprocess % (command_desc, proc.returncode, cwd)) InstallationError: Command python setup.py egg_info failed with error code 1 in venv/build/psycopg2

The error looks as if you do not have Django in the venv python path.

You can confirm that it is part of your venv python install using a couple of ways:

If you used PIP to install you can verify that the package is installed using pip freeze

Also check in lib/python2.7/site-packages/ of the venv there should be a django directory in there. This is the directory that is part of the PYTHONPATH for your venv.

If you cannot find the modules in there of have installed them in a different path. Then you will need to make sure that the path is part of the PYTHONPATH of the venv.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM