ImportError: Couldn't import Django

前端 未结 22 1805
无人共我
无人共我 2020-12-05 01:59

I\'ve already configured virtualenv in pycharm, when using the python manage.py command, this is error shown:

E:\\video course\\Python\\code\\web_worker\\MxO         


        
相关标签:
22条回答
  • 2020-12-05 02:41

    I faced the same problem when I was doing it on windows 10. The problem could be that the path is not defined for manage.py in the environment variables. I did the following steps and it worked out for me!

    1. Go to Start menu and search for manage.py.
    2. Right click on it and select "copy full path".
    3. Go to your "My Computer" or "This PC".
    4. Right click and select "Properties".
    5. Select Advanced settings.
    6. Select "Environment Variables."
    7. In the lower window, find "Path", click on it and click edit.
    8. Finally, click on "Add New".
    9. Paste the copied path with CTRL-V.
    10. Click OK and then restart you CMD with Administrator privileges.

    I really hope it works!

    0 讨论(0)
  • 2020-12-05 02:42

    Instead of creating a new virtual environment, you just have to access to your initially created virtual environment when you started the project.

    You just have to do the following in your command line:

    1)pipenv shell to access the backend virtual environment that you have initially created.

    2) Then, python manage.py runserver

    Let me know if it works for you or not.

    0 讨论(0)
  • 2020-12-05 02:43

    The problem is related to this error: Execution Policy Change

    Start virtualenv by running the following command:

    Command Line C: \ Users \ Name \ yourdjangofilesname > myvenv \ Scripts \ activate

    NOTE: On Windows 10, you may receive an error by Windows PowerShell that the implementation of these scenarios is disabled on this system. In this case, open another Windows PowerShell with the "Run as Administrator" option. After that, try typing the following commands before starting your virtual environment:

    C:\WINDOWS\system32> set-executionpolicy remotesigned

    Execution Policy Change: The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at http://go.microsoft.com/fwlink/?LinkID=135170.

    Do you want to change the execution policy? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A

    After selection Y(es), close the Powershell admin window, and then go back to the Powershell Window(where you got the error) and run the command again.

    > myenv\Scripts\activate and then python manage.py runserver 8085 ,

    (8085 or any number if you want to change its default port to work on otherwise you dont need to point out anything. )

    0 讨论(0)
  • 2020-12-05 02:44

    You need to install Django, this error is giving because django is not installed.

    pip install django
    
    0 讨论(0)
  • 2020-12-05 02:46

    if you don't want to deactivate or activate the already installed venv just ensure you have set the pythonpath set

    set pythonpath=C:\software\venv\include;C:\software\venv\lib;C:\software\venv\scripts;C:\software\venv\tcl;C:\software\venv\Lib\site-packages;

    and then execute

    "%pythonpath%" %venvpath%Scripts\mytestsite\manage.py runserver "%ipaddress%":8000

    0 讨论(0)
  • 2020-12-05 02:48

    I think the best way to use django is with virtualenv it's safe and you can install many apps in virtualenv which does not affect any outer space of the system vitualenv uses the default version of python which is same as in your system to install virtualenv

    sudo pip install virtualenv
    

    or for python3

    sudo pip3 install virtualenv
    

    and then in your dir

    mkdir ~/newproject

    cd ~/newproject

    Now, create a virtual environment within the project directory by typing

    virtualenv newenv
    

    To install packages into the isolated environment, you must activate it by typing:

    source newenv/bin/activate
    

    now install here with

    pip install django
    

    You can verify the installation by typing:

    django-admin --version
    

    To leave your virtual environment, you need to issue the deactivate command from anywhere on the system:

    deactivate
    
    0 讨论(0)
提交回复
热议问题