0

I am attempting to configure a virtual environment on a Windows machine with virtualenv and I have been unable to to run manage.py

I reviewed a few other stackoverflow answers (Running django in virtualenv - ImportError: No module named django.core.management?) and was unable to resolve the issue that I am having.

Here is where I am at...

C:\Users\tyarboro\Documents\Project (master)
(venv) λ pip freeze
Django==1.7
django-admin-sso==2.1.0
django-social-auth==0.7.28
httplib2==0.9.2
json2html==1.0.1
oauth2==1.9.0.post1
oauth2client==2.2.0
pyasn1==0.1.9
pyasn1-modules==0.0.8
python-openid==2.2.5
rsa==3.4.2
six==1.10.0

C:\Users\tyarboro\Documents\Project (master)
(venv) λ manage.py
Traceback (most recent call last):
  File "C:\Users\tyarboro\Documents\Project\manage.py", line 9, in <module>
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

I have attempted the following modifications to the manage.py

  1. Removed the first line of the file #!/usr/bin/env python
  2. Set the sys.path.append to the directory that contains the site-packages in my virtual environment. sys.path.append('C:\Users\tyarboro\Documents\Project\venv\bin\activate\Lib\site-packages')

I think the issue is that the virtual environment is running Python outside of the virtual environment instead of within the virtual environment. Any suggestions on how to fix this?

Thanks!

yarrsmash
  • 5
  • 3

1 Answers1

0

Try to install Django using built-in pip module:

 pip install django

This command should install packages into site-packages directory.

refer this doc : install-python-django-on-windows

Emil George James
  • 1,181
  • 1
  • 10
  • 20
  • That was one of the first things I tried. C:\Users\tyarboro\Documents\Project\venv\bin\activate\Lib\site-packages (master) (venv) λ pip install django Requirement already satisfied: django in c:\users\tyarboro\documents\project\venv\lib\site-packages – yarrsmash Jul 21 '17 at 15:55
  • @yarrsmash Try this `python -c "import django; print(django.get_version())"` to check if Django is installed on your PC or your virtualenv if you're using one.If installed then export it using this `export PYTHONPATH=/usr/local/lib/python2.7/site-packages`. – Emil George James Jul 21 '17 at 16:27
  • Thanks! The issue was that I was using the wrong version of Python for the project. It required python2 and not python3 which I had installed. I installed python2 and configured my machine to support running both versions by following the stackoverflow discussion here: https://stackoverflow.com/questions/3809314/how-to-install-both-python-2-x-and-python-3-x-in-windows-7 & here: https://www.reddit.com/r/learnpython/comments/3l5pc9/using_python_3_and_python_2_on_the_same_machine/ – yarrsmash Jul 25 '17 at 23:38