It is installed when pip is installed, but it cannot be imported. It's a simple story, but for example
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'django'
I get an error when I try to import django. The content of the error remains the same, but the module is not found.
I wondered if there was no django in the first place, and when I piped it,
C:\Users\aaa>pip install django
Requirement already satisfied: django in c:\users\aaa\anaconda3\lib\site-packages (3.0)
Requirement already satisfied: sqlparse>=0.2.2 in c:\users\aaa\anaconda3\lib\site-packages (from django) (0.3.0)
Requirement already satisfied: asgiref~=3.2 in c:\users\aaa\anaconda3\lib\site-packages (from django) (3.2.3)
Requirement already satisfied: pytz in c:\users\aaa\anaconda3\lib\site-packages (from django) (2019.3)
Since it is already satisfied, it is said that it is already satisfied. That simply means that the path doesn't go through.
You can check the path in sys.path
>>> import sys
>>> import path
>>> pprint.pprint(sys.path)
['',
'C:\\Users\\aaa\\Anaconda3\\python37.zip',
'C:\\Users\\aaa\\Anaconda3\\DLLs',
'C:\\Users\\aaa\\Anaconda3\\lib',
'C:\\Users\\aaa\\Anaconda3',
'C:\\Users\\aaa\\Anaconda3\\lib\\site-packages',
'C:\\Users\\aaa\\Anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\aaa\\Anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\aaa\\Anaconda3\\lib\\site-packages\\Pythonwin',
Sure, I don't have the django path "django in c: \ users \ aaa \ anaconda3 \ lib \ site-packages (3.0)".
Once you know this, all you have to do is add the path to your environment variables. You can add it to an environment variable with sys.path.append,
sys.path.append("c:/users/aaa/anaconda3/lib/site-packages (3.0)")
If you thrust it in, check it again
>>> pprint.pprint(sys.path)
'c:/users/aaa/anaconda3/lib/site-packages (3.0)'
Is OK if is added.
>>> import django
>>> print(django.get_version())
3.0
I was able to confirm that django can be used.
By the way, when I try to copy and paste it into an environment variable, I get this error.
>>> sys.path.append("c:\users\aaa\anaconda3\lib\site-packages (3.0)")
File "<stdin>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX escape
>>> sys.path.append("c:/users/aaa/anaconda3/lib/site-packages (3.0)")
This is because the \ mark is an escape, so \ u recognizes it as an escape sequence. sys.path.append ("c: \ users \ aaa \ anaconda3 \ lib \ site-packages (3.0)") You can do it with sys.path.append ("c: /users/aaa/anaconda3/lib/site-packages (3.0)").
Recommended Posts