Why doesn't Pydev find Django? - python

I have Django installed. I also have django-admin.py in my python-2.7 folder. I can import django using my Python shell (DreamPie). But I can't create a new Django project in Pydev. When trying to create a new Pydev Django Project (choosing python2.7 as the interpreter) I receive the following error message:
I went to the link in the message and I have all the pre-requisite to getting started in Django: Django is installed and import django properly works (in the shell).

In Eclipse:
Window --> Preferences --> Interpreter - Python.
Make sure to choose Python2.7 as the interpreter.
Now, click New Folder. Browse to find the path to django (in this case: C:\Django-1.2.5\django).
OK --> Apply --> OK.
That's it. You can create a new Django project.

What helped me (adjust dir and file names according your installation):
I created copy of file Django-1.3-py2.7.egg-info from C:\Python27\Lib\site-packages\ in the same folder with extender *.egg.
Then, in Eclipse dialog
Window -> Preferences -> PyDev -> Interpreter-Python
I used buton New Egg/Zip(s) in order to add this newly created file to System PYTHONPATH list.
This way Eclipse found Django.

I refer to Fabio Zadroznys answer which should work for all of you.
Probably the PYTHONPATH configured in your interpreter is not correct...
I.e.: if you have a structure with
/my/path/django
/my/path/django/init.py
you have to make sure that
/my/path
is added to the PYTHONPATH (and /my/path/django is NOT!!!)
Another thing to note is that right after installing Django, you just have to do a refresh >in your interpreter so that it's recognized (go to the interpreter preferences page, press >'apply' and choose the interpreters to be re-analyzed -- there are already plans to make >this automatic in one of the upcoming releases, but right now you have to do that manually >because the interpreter is analyzed when you configure it and 'set in stone').
LINK:
pydev does not recognize django installation

You can follow any python version. But in your case Django is not installed globally.
Requirement is you need to have Django installed in system.
For checking the django is installed or not
open CMD / terminal (Assuming that Python is already installed)
$ python
$ import django
$ django.VERSION
You can see the output like this. Here I am using Django 3.1
(3, 1, 0, 'final', 0)
Then in the Preferences --> Interpreter - Python --> Click new and add the location where python.exe or Python application resides. Make sure you are naming the Interpreter appropriately for future reference.
Then restart the eclipse and go to New --> Other --> PyDev --> PyDev Django Project
Name your project
Select the Interpreter that you previously created from the drop down.
The above fixes your issue.

not working for me. the attached screensnap shows that django is importable from the pydev shell, and that the path to it is in pydev's SYSTEMPATH.
(since folks have mentioned virtualenv in other questions, i'll mention this is occuring within a virtualbox but i don't think that matters?)

It needs to be in the PATH or in the /usr/bin

Related

PyCharm 2018 Python Unresolved Reference 'django' VirtualEnv

I have the newest PyCharm version (2018) and the latest Django version (2.1) and Python (3.6)
When I want to import something in PyCharm from Django:
from django.urls import url
I get an error message under django stating:
Unresolved reference 'django'
I created a virtual environment and I ran a project on it, the most famous one (polls) and it ran very well.
But now I noticed that I have this error, what is the solution?
Thank you in advance.
The current virtual environment you are using does not have django installed in it. Installing it for the current environment or using a project interpreter which have django installed should resolve the issue.
1. Installing Django on your current virtual environment via pycharm settings.
Go to Settings > Project > Project Interpreter and click the
green plus sign on the right hand side (install option).
Search for django in the search bar of the available packages dialog
and select it.
Select the install package option at the bottom.
2. Installing Django on your current virtual environment via pycharm terminal.
Click on the pycharm terminal and install django using
pip install Django
3. Changing the current project Interpreter.
Go to Settings > Project > Project Interpreter and click on the project interpreter drop down menu.
Choose a project interpreter which have django installed.
I had this problem specifically with a tutorial that uses an SRC folder. I learned that the SRC folder needs to be marked as a "sources root" in Pycharm. Once done, then the error flagging goes away.
Try Django Tutorial
I had this problem but none of the answers above and in other posts worked. I use the right interpreter and Django is well installed (in a venv).
I restored default settings with File > Manage IDE settings and this corrected the error.
I suppose the last update of PyCharm went wrong and this restarted everything well.
/!\ As #Vegas precised it in the comment, all configurations will disappear

Using Django with Eclipse - making sure Django is installed correctly

all.
Note that I'm a newbie to Django and Python. I keep feeling like I'm missing very small details, and they're probably related to Eclipse's GUI.
Python is installed here:
C:\Python32
...and Django is installed here:
C:\Python32\Lib\site-packages\django
Note that I ran python from a command prompt to check my Version of Django. It worked. I'm running version 1.5.
Problems come when I try to create a new Django project using Eclipse. This is what happens:
I'll specify that I want to create a new Django project
I'll select my interpreter, give my project a name, and select a grammar version (3.0)
"Add Project Directory to PYTHONPATH" is selected
When I click "Next" I get an error message saying that "Django wasn't found".
But when Python is run from a command prompt (and I "import Django"), Python seems to know where Django is. Python doesn't seem know where Django is when I try to create a Django project in Eclipse.
I feel like I'm missing something very, very small - an environment variable or something. Can anyone help? Thanks in advance.
Make sure that you have added the Django install path to the system PYTHONPATH list. For PyDev in Eclipse, the python path can be found under "Window->Preferences->PyDev->Interpreter - Python"
Click on the New Folder button, navigate to the Django install path (it will be found at /usr/lib/python2.7/dist-packages/django if you installed it to the default directory), and click OK

PyDev code analysis missing

I have installed Eclipse 3.7.2 from APT in Ubuntu 12.04, and installed PyDev in Eclipse. First, it warns unused import and unused wild import, but it no longer displays them today. However, it can display errors like missing parenthesis.
I created a new user, and installed PyDev using that user, problem still happens. How can I enable them for warnings? I have not change the code analysis settings.
list all operations could solve it here, for others convenience, and make this question closed
remove the project and recreated it, and this time the project dir is the the PYTHONPATH
remove your python interpretor settings, and set it again in eclipse - window preference - pydev -interpreter Python, refresh the pydev index
Project -> Properties -> PyDev -PYTHONPATH, all is empty. I then "add source folder"
I had the same problem. Went to project properties > pydev - PYTHONPATH, then setting the source folder did it for me !

How to select Python version in PyCharm?

I have PyCharm 1.5.4 and have used the "Open Directory" option to open the contents of a folder in the IDE.
I have Python version 3.2 selected (it shows up under the "External Libraries" node).
How can I select another version of Python (that I already have installed on my machine) so that PyCharm uses that version instead?
File -> Settings
Preferences->Project Interpreter->Python Interpreters
If it's not listed add it.
I think you are saying that you have python2 and python3 installed and have added a reference to each version under Pycharm > Settings > Project Interpreter
What I think you are asking is how do you have some projects run with Python 2 and some projects running with Python 3.
If so, you can look under Run > Edit Configurations
PyCharm 2019.1+
There is a new feature called Interpreter in status bar (scroll down a little bit). This makes switching between python interpreters and seeing which version you’re using easier.
Enable status bar
In case you cannot see the status bar, you can easily activate it by running the Find Action command (Ctrl+Shift+A or ⌘+ ⇧+A on mac). Then type status bar and choose View: Status Bar to see it.
This can also happen in Intellij Ultimate, which has PyCharm integrated. The issue is as diagnosed above, you have the wrong interpreter selected.
The exact method to fix this for any given project is to go to Project Settings...Project and adjust the Project SDK. You can add a New Project SDK if you don't have Python 3 added by navigating to the python3 binary. This will fix the errors listed above. A shortcut to Project Settings is the blue checkerboard-type icon.
You can also add Python 3 as the default interpreter for Python projects. On OSX this is in File..Other Settings...Default Project Structure. There you can set the Project SDK which will now apply on each new project. It can be different on other platforms, but still similar.
Go to:
Files -> Settings -> Project -> *"Your Project Name"* -> Project Interpreter
There you can see which external libraries you have installed for python2 and which for python3.
Select the required python version according to your requirements.
Quick Answer:
File --> Setting
In left side in project section --> Project interpreter
Select desired Project interpreter
Apply + OK
[NOTE]:
Tested on Pycharm 2018 and 2017.

pydev not recognizing python installation with django

I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash.
When I try creating a django project in pydev, I get an error: "Django not found."
What could the problem be?
I had the same problem and this is what I did just after installing eclipse:
Preferences > Interpreter Python
Pressed Auto-config
Selected /Library/Python/x.x/site-packages, which was not selected
(some django folders were in there, persumably the installation)
Clicked apply / OK
Creating a Django project afterwards should be ok.
Good Luck!
go in the menu to window -> preference -> pydev -> Interpreter - Python ; and add the python interpreter there, if you installed the django in a virtual environment you should add the python interpreter of the virtual env ; after adding the interpreter by clicking on new you should now click on Apply , you should see now all the system libs from PYTHONPATH added there between them Django .
hope this will help
Jaffa,
You might have configured your python interpreter in Eclipse prior to installing Django in python.
So what you have to do now is in Eclipse remove the Python interpreter and add it again (now that it has Django installed) and all should work ok.
I was having this same exact problem today, and I just wanted to add some notes to help people out. You can follow the instructions of antonkeren above, but there's one thing to note that was not mentioned. After adding the django directory to the path you must QUIT ECLIPSE OR APTANA STUDIO. After you restart it and try to create a django project it will work.
I stumbled upon this only yesterday myself: Django must not be among the system libraries for this to function...
I had the same problem and had solved it by adding the python home directory to the PATH variable and reconfigure the python interpreter on pydev.
Use auto config in the preferences option and then click apply and then ok.
If everything is done as said above, and still showing "Django not found" while your are trying to create django project, let try to double click 'django-admin' python file that in scripts folder of python. And try to create django project
I think I've got the same problem, Eclipse 3.5.2 on Fedora. In my PyDev Python interpreter settings I've got the site-packages/django folder (site-packages/django/bin too, just in case), but when I try to create a django project I get an error dialogue saying "It seems that the selected interpreter does not have Django available". Looks like I'm going to have to use Eric4, which is a pity because I can't get that working at all on my Windows rig!
Unless I manage to understand the cryptic advice above, "Django must not be among the system libraries for this to function..."
Same problem I have faced today. I took help from these answer.
but in my case it didnt work.
There is small modification in #antonkeren answer.
1) Go to Preferences. Windows > preferences.
2) Search for Pydev
3) Select Python Interpreter
4) Pressed Quick Auto-config
5) now download www.djangoproject.org/downloads django tar and extract on any location.
6) now click on Folder in "Libraries tab" of "System PYTHONPATH" and select your extracted django project folder location.
7) Click on apply and ok.
Creating a Django project afterwards should be ok.
Cheers...!!

Categories