简体   繁体   中英

How to setup Django inside virtualenv on Windows?

Any Windows python developers here?

I created a virtualenv, activated it and installed django . If I run pip3 list , it shows Django (2.0.3) as installed. The problem is when I try and use django, it never works, it just returns "no module django."

When I try pip3 install django again, it says it's already installed at myname\\envs...\\site-packages. But when I use the django command it never looks at this path, it looks at appdata/local/programs/python/python36-32/python.exe (ie not the virtualenv but the python installation itself).

Anyone have any ideas?

Maybe you have tried to use pip3 which located in your real python environment. But actually your django has been installed in virtual environment. From your example, maybe you should check the python interpreter something like this: venv/bin/python3.4.

By the way, before you use django-admin command, you should make sure you have already in virtual env.

For example, if you are in virtual env, it will be someting like this:

(venv)Mac:myproject michael$ pip install jinja2
...
Successfully installed jinja2-2.7.3 markupsafe-0.23
(venv)Mac:myproject michael$ python myapp.py
...

If you want to get into the real python environment:

(venv)Mac:myproject michael$ deactivate 
Mac:myproject michael$

So, you should make sure you have been in the same environment with both packages and interpreter.

在激活virtualenv python环境后,应使用pip

Refer to this section of the documentation https://docs.djangoproject.com/en/2.0/intro/contributing/#getting-a-copy-of-django-s-development-version

For Windows users Using the built-in venv module will not work if you are also using the Git Bash shell on Windows, since activation scripts are only created for the system shell (.bat) and PowerShell (.ps1). Use the virtualenv package instead:

$ pip install virtualenv
$ virtualenv ~/.virtualenvs/djangodev

Then you start using your virtual environment with

workon <<your_virtual_env_name>>

Then every package you install will be within this environment

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