PyDev code analysis missing - python

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 !

Related

PyCharm cannot find the packages in virtualenv

I have the latest PyCharm CE and am using it with virtualenv. I have defined the interpreter as the interpreter in the virtualenv. The Project Interpreter window in PyCharm lists all the packages I have installed. I confirmed this by running pip freeze > requirements.txt and running through the packages manually.
My problem is that PyCharm won't find certain includes in its editor windows, like Flask-Login:
In from flask.ext.login import current_user, login_user, logout_user, login_required the includes current_user, login_user, logout_user, login_required are all marked as unresolved references.
Am I missing something?
The problem may lay in PyCharm picking up faulty 'Interpreter Paths' for your virtual environment. Go here:
PyCharm (menu) -> Preferences (Menu option)
-> Project: <name> (Dropdown)
-> Project Interpreter (Menu option)
-> 'Settings' button (Looks like a gear)
-> More (Menu option)
-> Select your virtualenv interpreter
-> Click 'Show paths for interpreter' button (on bottom of list window)
Now that you're in this (admittedly tortuously found) location, you should see paths being used by this interpreter. If my theory is correct, these are pointing to global system locations. To add the virtual environment paths, you should click the + button and add corresponding paths that exist inside your virtual environment. Once you're done with this, it's a good idea to select the global system paths and click - to remove them. Click apply, and go to File -> Invalidate caches / Restart to reload PyCharm.
This should get your interpreter to be pointed to the correct location for the libraries you've installed into your virtualenv, and you should no longer be getting the import error. Note that even with this fix you will not see your libraries under the Project Interpreter, but they should be being loaded.
In the newest version of PyCharm (2016.1.4 in my case):
Settings
Project: name of project
project Interpreter
at the right side there will be a dropdown where you can choose the interpreter. There should be venv options.
See image below for better explanation (like they said, 1 picture worth thousands word)
I was also facing the same issue (includes are still not being found) even after Nathaniel Ford and dieend's correct suggestion. Make sure that your run/debug configuration as correct python interpreter selected:
I noticed that every time I open a different project it still has the venv from the project I was previously working on.
What I do is:
ctrl-alt-s (to go into preferences), then Project Interpreter/settings (gear icon), show all, then remove all the venv environments that aren't your current project (use the - sign). Restart, and you should be good to go.
Also note the accepted answer is no longer applicable to PyCharm menu structure. It is now File > Settings > Project > Project Interpreter > Gear Icon > Show All
The following steps detail the "nuclear" option:
Delete your project virtual environment directory (e.g. /venv)
Delete all other interpreters listed in menu option accessible by the route listed at the top of this post.
Close PyCharm
Delete the .idea directory in your project folder
Restart PyCharm, opening the project folder.
Go through the process of configuring a new interpreter.
That will pretty much get you starting from scratch.
Open up Preferences -> Project -> Project Interpreter, do you see the module there?
If yes, you might have another file somewhere in your project have the same name as flask.ext.login, this prevents pycharm from locating the actual module.
If no, you can click on the ... beside your interpreter and select more..., select your interpreter and at the bottom (beside the filter), click the Show paths for the selected interpreter, you can add the path of your module there.
For me, the easiest solution was to open the project in the root directory (my project has a server and client directories, thus the root directory contained both of them). When you open the project in the root directory, it is able to find the dependencies without messing with pycharm settings as it uses them by convention.
My two cents on this topic as I struggled myself with it recently.
Nathaniel Ford's answer is the good one except that this part:
-> Select your virtualenv interpreter
was unclear to me.
I tried several times with
~/.virtualenvs/python-audition-2.9/bin/python
whereas it only worked with
~/.virtualenvs/python-audition-2.9/local/bin/python
Notice the .../local/... in the latter path? It was really important in my case. And don't forget to File -> Invalidate caches / Restart to reload PyCharm.
Adding the lib directory in my virtual environment to sources in the PyCharm CE settings helped me.
My steps:
Preferences -> Project: -> Project Structure
Scrin1
Select the directory where you installed the libraries. In my case, this is "lib".
Mark the directory as "source".
Scrin2
After these actions, all my libraries were correctly imported into the py files I needed.
Easy solution: (PyCharm 2022.2.3) and Python 3.11.0 on Win11:
Create new venv Environment for the project, DO NOT inherit site-packages
Check, if jupyter-server uses new venv (Settings->Language&Frameworks->Jupyter->Jupyter Server)
Install all required packages (inbcluding jupyter!) to venv (e.g., requirements.txt and PyCharm)
Worked fine for me.
Goto /venv/bin/ and check all activate scripts. You venv path might be wrong.
I was not able to assign existing virtual environment to my project, but after going to
File -> Settings -> project interpreter-> show all-> click on '+'
to create a new virtual environment or we can choose the existing virtual environment, I am able to assign and use the existing virtual enviroments.

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.

Why doesn't Pydev find Django?

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

IDE don't see all the functions

i'm using Elcipse+PyDev and Pyscripter sometimes for Python 2.7
Yesterday i installed PyTables from compiled binaries and :
import tables
h5f = tables.openFile(r'D:\sample.h5','w')
h5f.createGroup('/','Box')
h5f.
So, when I type "h5f." IDE don't show me all the methods, only a few!
Can't do anything with It, installed PyTables few times,same result...
Method h5f.CreateGroup() works perfectly, but IDE dont see it so don't display it in drop-down list! Eclipse and Python both behave same...
The thing with Pydev and Eclipse is that when you install a new package or library and if you want to use the auto-complete with it, you will have to recreate the system PYTHONPATH in eclipse.
For that go to: Window -> Preferences -> Pydev -> Interpreted Python and in the tab libraries, in System PYTHONPATH you will not see your new installed library because pydev just do a copy of the PYTHONPATH the first time that you have configured and now each time you installed a new package you will have to resynchronize pydev with the new PYTHONPATH.
So to resynchronize you will have to click on the button Apply so that eclipse export (again) all the library (between them your new installed one) from PYTHONPATH to eclipse.
So now eclipse should know your library and you should work with it just fine.
Hope this will help :)

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