简体   繁体   中英

Why doesn't “python” command work in virtualenv?

Before asking, I should mention that this is NOT a problem or a bug, this is just a question to widen my knowledge.

When I was working on a Django project (I'm quite new to all these things so don't beat, please) I activated my virtualenv, installed django module and started a new Django project by using django-admin.py startproject myproject . That worked. But then I cd to myproject and tried to run python manage.py startapp firstapp , and failed.

I caught ImportError: no module named 'django' . The problem was solved by simply typing ./manage.py startapp firstapp . What the heck is that? Why doesn't python command work? Python version is 3.5.2.

Because of the way virtualenvs work, Django was not 'installed' in said env.

The reason ./manage.py startapp firstapp worked is because the ./ indicated that it was an executable file, and hence handled by the system as such. That way, modules are accessible, as the program is ran outside of the env

Hope this helped!

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