Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 888  / 2 Years ago, thu, april 28, 2022, 10:03:07

My PyCharm IDE doesn't automatically create a venv directory so I have to manually create my own.
My venv directory comes up as ignored. This is normal.
A possible solution is found the comment section.
When creating a PyCharm Project Django and virtualenv were installed. I did not have to install Django. So now Python3 needs a clean up.



Update: I've been having issues with PyCharm IDE for a while now and I want to be sure is the sys.path:
From PyCharm IDE terminal:



>>> python3
>>> import sys
>>> print(sys.path)
['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/home/name/Projects/bye/venv/lib/python3.7/site-packages', '/home/name/Projects
/bye/venv/lib/python3.7/site-packages/setuptools-40.8.0-py3.7.egg', '/home/name/Projects/bye/venv/lib/python3.7/site-packages/pip-19.0.3-py3.7.egg']


Despite the directory being created I still get this result:



 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?"


enter image description here



The ImportError is generated by line 6 of the following Python 3 code, not necessarily by the code but rather by the from django.core.management import on line 4.



    def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Example.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise 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?"
) from exc
execute_from_command_line(sys.argv)

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Example.settings')
application = get_wsgi_application()
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Example.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'Example.wsgi.application'


enter image description here



enter image description here


More From » python3

 Answers
4

These are the results of print(sys.path)



$ python3
>>> import sys
>>> print(sys.path)
['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/dist-packages',
'/usr/lib/python3/dist-packages']


The results of your print(sys.path) show lots of user-made modifications, possibly the result of multiple unrecommended package management decisions in your Ubuntu 19.04.


[#5030] Friday, April 29, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irripri

Total Points: 164
Total Questions: 111
Total Answers: 107

Location: South Georgia
Member since Sun, Aug 8, 2021
3 Years ago
irripri questions
Mon, Aug 29, 22, 03:19, 2 Years ago
Thu, Mar 30, 23, 01:56, 1 Year ago
Wed, May 31, 23, 01:37, 12 Months ago
Thu, Dec 30, 21, 08:53, 2 Years ago
Sat, Mar 26, 22, 04:01, 2 Years ago
;