When I start a new Django Project it works perfectly but after I shutdown or restart my PC it does not work. Even though I have activated my virtual environment it keeps giving me errors.
This what the error says:
Traceback (most recent call last):
File "C:\Users\SUCCESS-AKINYEMI\Desktop\studybud\manage.py", line 11, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\SUCCESS-AKINYEMI\Desktop\studybud\manage.py", line 22, in main()
File "C:\Users\SUCCESS-AKINYEMI\Desktop\studybud\manage.py", line 13, in main
raise ImportError( ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
I tried it on another laptop and it worked, but it is not working on my own laptop.
make sure that python is added to the path
in windows try
windows logo + pause -> Advanced system settings -> Environment variables
if python it's not on the list add it.
for Value insert something like this
C:\Users\username\AppData\Local\Programs\Python\Python310\Scripts\
also make sure that you use the keyword py in your commands
for example :
py manage.py runserver
Related
When I first ran the server everything was fine and the project was running properly. But after few days when I ran the server again, it gave me an error
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\Django Project\first\manage.py", line 11, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\Django Project\first\manage.py", line 22, in <module>
main()
File "C:\Users\Admin\Desktop\Django Project\first\manage.py", line 13, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
To be specific, I'm on Windows 10, using VS Code as my IDE (I've not setup any virtual environment).
Django version installed - 3.2.9
Python version installed - 3.10.0
PIP version installed - 21.2.3
Here is a screenshot of my Environment Variables
[
I don't know what the problem was. Thanks to everyone for their suggestions. I deleted the project and created a new one and it worked. I hope I won't face any such issue while working on a big project!
I'm new to using Django & Python and am having some difficulty trying to get my manage.py application to run in a virtual environment.
I am receiving the following errors at the top of my models.py file:
I initially thought that this was an issue with pylint not pointing at the right environment (when I switch my Python interpretter to the one outside of the virtual environment, the pylint errors disappear); however, whenever I try to run my server, I get the following error:
(.venv) tjmcerlean#LAPTOP-RKLCBQLO:/mnt/c/Users/tjmce/Desktop/Git/CS50w/Project 2/commerce$ python manage.py runserverTraceback (most recent call last):
File "manage.py", line 10, in main
from django.core.management import execute_from_command_line
File "/mnt/c/Users/tjmce/Desktop/Git/CS50w/Project 2/commerce/.venv/lib/python3.8/site-packages/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
ModuleNotFoundError: No module named 'django.utils'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 12, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
This error appears to suggest that the virtual environment is not activated. However, I activated it using the location of the virtual environment (.venv/bin/activate) and saw that the bash terminal now displays (.venv):
Additionally, when using the (pip freeze) command, I can see that Django is installed within the virtual environment too:
I'm lost as to why the server won't run and would really appreciate any advice.
Thank you!
Calling django.__file__ in activated env reveals the real path:
python -c "import django; print(django.__file__)"
it should looks like /usr/local/lib/python3.8/site-packages/django/__init__.py
then re-check PYTHONPATH environment variable.
Maybe you've installed 2 Django in venv and system-wide but in some of them there is no db. And also remove all of *.pyc files in your working folder.
The problems occur when you don't include a path in virtualenv.
Try adding the path of python on your vscode.
Or, try to install and uninstall the Django projects.
I have added celery in my miniconda distribution. But when I try to run it I get the following error
Traceback (most recent call last):
File "C:\Miniconda2\Scripts\celery-script.py", line 6, in <module>
sys.exit(main())
File "C:\Miniconda2\lib\site-packages\celery\__main__.py", line 29, in main
from celery.bin.celery import main
ImportError: No module named celery
entering the python env through miniconda (C:\Miniconda2 python.exe) and importing celery works
>>import celery
>>
I have also Python 2.7 installed which does not have celery. Do you think its that?
You've answered your own question. In the first code block you're most likely running your python in C:\Python27. In the second code block you're actually running the python with celery in it.
You should read up on managing and activating conda environments. http://conda.pydata.org/docs/using/envs.html
I installed mod_python, I try to run python script like:
from mod_python import apache
It show me the error message:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
from mod_python import apache
File "D:\Python27\lib\mod_python\apache.py", line 55, in <module>
import _apache
ImportError: No module named _apache
I don't know why?
My enviroment:
Windows XP, Python 2.7.2
If you don't get any help here, try the mod_python mailing list:
http://www.modpython.org/live/mod_python-2.7.8/doc-html/installation.html
Its probably that the script location is not added to your path.
try:
import sys
sys.path
sys.path.append('/path/to/the/mod_python.py')
If this doesn't work, it was probably not installed correctly.
If you want to add it to your system path permanently so you don't have to use the code above every time check out this SO question.
I'm trying to use VirtualEnv for a Flask app that I'm creating since everyone has recommended me to do so. After creating my virtual environment, I installed the libraries that I needed using pip while the environment was activated. I'm running into ImportError problems with this script. The code works fine when I'm not in the virtual environment.
My script:
#!/usr/bin/python
import sc2reader
...
...
When I try to run it I get this:
(flaskapp)xxxx#xxxx-VirtualBox:~/flaskapp/bin$ ./test.py
Traceback (most recent call last):
File "./test.py", line 3, in <module>
import sc2reader
ImportError: No module named sc2reader
I've tried changing the shebang to reflect my VirtualEnv path for Python, but that didn't fix anything. The library is found in my site-packages folder in my virtual environment, so I'm not sure why I'm getting the ImportError.
I've never used VirtualEnv before so I'm assuming I configured it wrong so it's not seeing my site-packages.
Try using
#!/usr/bin/env python
as the shebang.
If that does not work, try seeing what is the output of which python.