[Fixed]-Unable to import Django.shortcuts

30πŸ‘

If you look in your status bar you will notice you selected your global install of Python 3.7.4 and not a virtual environment. If you click on that you can then choose your virtual environment that you installed Django into.

πŸ‘€Brett Cannon

25πŸ‘

enter image description here

You selected your global install of Python 3.7.4 and not a virtual environment. If you click on that you can then choose your virtual environment that you installed Django into.

enter image description here

πŸ‘€Raghavendara

4πŸ‘

Screenshot

Solution 2: (open VS Code from an activated virtual environment):

  1. Open the terminal window
  2. Activate the relevant python virtual environment
  3. Ensure Pylint is installed within this virtual environment pip
    install pylint
  4. Close all instances of VS Code
  5. Launch VS Code from within this terminal window

(this will ensure the VS Code process will inherit all of the Virtual Env environment settings)

πŸ‘€Raj Kushwaha

4πŸ‘

I have the same problem. after westing hours I found this solution, so to solve this problem follow these steps:

  1. open VSCode
  2. go to the View tab and click on Command Pallete
  3. search: Python: select interpreter
  4. click on Enter interpreter path then click on Find
  5. go to the virtual environment folder then go to the Scripts folder
  6. select python.exe
  7. after that select Python 3.x.x (β€˜env’)
  8. finish πŸ™‚

1πŸ‘

It’s very common in visual studio code, don’t bother about it much it’s just warnings. I also faced those errors while working on it. Just go ahead and complete your project first and if it still causes an error then i can guide you better.

Try these simple projects of mine to check everything is working fine or to check your django installed properly or not.

Hello world project:
https://github.com/YashMarmat/Hello-world-App-django.git

πŸ‘€Yash Marmat

1πŸ‘

This occurs because of change in Django version, using other environment which might exist in your system.

πŸ‘€raven404

0πŸ‘

import os in your settings.py file
enter image description here
Also, see which python version VSCode is using
I had Anaconda, Python 3.8, 3.9 in my system.

VSCode was using conda (base) virtual environment.

I was getting an Import error

I selected the correct path for Python 3.8 in VSCode Terminal

"C:\Users\******\AppData\Local\Python\Python38"

It ran successfully.

0πŸ‘

I fixed the problem by switching to my dev environment where I did install Django.

0πŸ‘

I had the same issue. But all I had to do was to select the correct Python interpreter by going into the VS Code command palette and selecting Python:Select Interpreter, and then selecting the correct interpreter. That means selecting the version of Python which you are working with and set the path for. Hope this helps!

-1πŸ‘

this problem cause from pylanc extention. just uninstall it

πŸ‘€Mohsen Kh

Leave a comment