0

I created a project in virtualenv on windows and then tried to run it and this error occurred:

    Traceback (most recent call last):
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
    super().execute(*args, **options)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\core\management\base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\core\management\commands\runserver.py", line 67, in handle
    if not settings.DEBUG and not settings.ALLOWED_HOSTS:
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
    self._setup(name)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\conf\__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\conf\__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'C:\\Python39\\Lib\\site-packages\\django\\conf'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Windows\System32\django\django_project\manage.py", line 21, in <module>
    main()
  File "C:\Windows\System32\django\django_project\manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\core\management\base.py", line 341, in run_from_argv
    connections.close_all()
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\db\utils.py", line 225, in close_all
    for alias in self:
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\db\utils.py", line 219, in __iter__
    return iter(self.databases)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\db\utils.py", line 153, in databases
    self._databases = settings.DATABASES
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__
    self._setup(name)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\conf\__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Windows\System32\django\.venv\lib\site-packages\django\conf\__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'C:\\Python39\\Lib\\site-packages\\django\\conf'

here's my apps versions


- asgiref    3.2.7
- Django     3.0.5
- pip        20.0.2
- pytz       2019.3
- setuptools 41.2.0
- sqlparse   0.3.1
  1. My files :
    • manage.py
    • django_project :
      • asgi.py
      • settings.py
      • urls.py
      • wsgi.py
      • init.py

I try building virtualenv in the project and still not working .

please help me :)

Sm_mE
  • 1
  • 1
  • Python 3.9 is an alpha release. I recommend you install the latest 3.8.x release (currently 3.8.2), create a new virtual env and install Django in that. If you're still stuck, please show the commands you used to create the virtual env, install Django and start runserver. – Alasdair Apr 23 '20 at 11:17

2 Answers2

0
  1. you have to activate your virtualenv

    source ~/your_virtual_env_directory/Scripts/activate

    1. run command in your project directory

    python manage.py runserver

0

Use pipenv for making virtual environment

steps:

1.) locate your project using terminal lets say cd/desktop/myproject

2.) then use the following command (you can change the django version if you like)

pipenv install django==3.0.1

then start the virtual enviroment using

pipenv shell

it will create your virtual enviorment something like this (myproject)$

3.) to quit virtual enviroment use

exit

4.) to start same virtual enviroment again use

pipenv shell
Community
  • 1
  • 1
Yash Marmat
  • 1,077
  • 10
  • 18