I'm using Eclipse (on the PyDev perspective), and I just installed (using pip) the python 'requests' module.
Eclipse is giving me an error warning on the 'import requests' line, saying that it is an unresolved import, but I've run it it imports just fine. (But the error message won't go away).
Its really bugging me, and I can't right-click and delete the error either. (The option is gray).
Is there any way to fix this? (Even if it involves manually removing the error?)
I know that there is a similar problem here:
Eclipse Pydev - Misdiplayed Import Error
but the answer to that was that PyDev had a bug specifically with PIL, so that is why I'm asking a different question.
Sometimes, PyDev is a little buggy... When it happens, I usually right-click on the folder containing the file in the PyDev Package Explorer, then "PyDev->remove error markers". And then re-run code analysis.
If it still doesn't work, try removing and adding again the directory to your requests module to the PyDev Path. As I said, PyDev is a little buggy...
You should manually configure properties of you PyDev project.
Right click on your project name, select PyDev - PYTHONPATH, then in External Libraries tab press Add source folder and choose the root directory of your library.
Related
I recently created a Python package which I use in most of my projects so I moved it to my user-site directory (python -m site --user-site). Everything works perfectly now except for the fact that PyCharm has disabled code inspection for it.
Is there any way for me to enable code inspection without moving the project back to a different directory?
It turns out it was because I didn't have an interpreter set for my project (and not that it was placed in a site-packages directory). I assumed that it did due to the fact that PyCharm didn't have it's usual "no interpreter configured for this project" alert. Finally figured it out when I went poking in the settings.
Eclipse Neon 4.6.0, PyDev 5.1.2, OS X El Capitan 10.11.6, GAE SDK 1.9.40
The project I am working on runs locally and on appspot.com, I'm trying to move to Eclipse from Pycharm to see if Eclipse works better for me. I have the PyDev plugin installed. The project works fine while running in debug mode too.
When the debugger pauses at a break point I get this warning on the console:
/Users/[my_user_id]/.p2/pool/plugins/org.python.pydev_5.1.2.201606231256/pysrc/_pydevd_bundle/pydevd_xml.py:85: RuntimeWarning: Parent module '_pydevd_bundle' not found while handling absolute import
While I have the debugger paused at any break point at all and I enter any valid or invalid command at the Python prompt I get the expect response from Python followed by this error:
Traceback (most recent call last):
File "/Users/[my_user_ID]/.p2/pool/plugins/org.python.pydev_5.1.2.201606231256/pysrc/_pydevd_bundle/pydevd_save_locals.py", line 35, in save_locals
ImportError: No module named _pydevd_bundle
My assumption is that the path to the _pydevd_bundle is somehow a problem but, the normal fixes are not getting it.
That path is:
/Users/[my_user_ID]/.p2/pool/plugins/org.python.pydev_5.1.2.201606231256/pysrc
I have checked that in Finder.
So far I have tried the following:
Reinstalled Eclipse & PyDev from alternate mirror sites in case there
was some corruption
Forced the path to the _pydevd_bundle into the system path.
At Preferences >> PyDev >> Interpreters >> Python Interpreter:
Added the path above to the PYTHONPATH list
Added all the modules under that /pysrc directory to the Forced
Builtins list
I've also tried going down to the module directory itself which
should not be needed since all the module directories have an
__init__.py file.
Before the reinstall I even tried commenting out the offending import
statement in the pydevd_save_locals.py file.
The only thing I have not tried is blowing away my entire Python install and starting from scratch with everything attached to that. Just more work with a 50/50 shot at a fix.
Since the debugger appears to work okay this might be more of an annoyance than anything else. But, it's potentially hiding other errors however. Any help would be appreciated.
Update: I upgraded the GAE SDK to 1.9.40, reinstalled Eclipse, and reinstalled PyDev, no joy.
My PyCharm 5.0.1 installation does not resolve references to any builtin modules or methods:
As you can see, I have installed python over cygwin.
I already tried:
reinstalling / updating the python installation (from 2.7.9 to 2.7.10)
reinstalling pycharm
adding a interpreter path to the python-skeletons in the pycharm installation directory (this was immediately removed by the ide when saving the settings, implying, that it already is embedded)
removing the interpreter (this removes the warnings, but also the code completion, and import asdflkjasd is valid as well)
adding various paths like /lib/python2.7/site-packages/ to the interpreter packages option
None of these improved the situation.
How can I fix this without installation outside of cygwin alltogether?
This is an update with a much better solution than my previous answer (which I completely missed that OP was asking for a solution that didn't require exactly what I suggested).
Like Carl commented above, updating python-skeletons is actually the way to go, however, if you're using Cygwin, the interpreter paths are a little wonky, and PyCharm won't always automatically add the right paths. For me, PyCharm handled it just fine in version 4.5.4, but not 5.0.4.
You'll find the python builtins in your Pycharm config directory, probably at:
C:\Users\[USERNAME]\.PyCharm50\system\python_stubs\-[RANDOM_STRING_OF_NUMBERS]
Just manually add this path (or paths) to your interpreter and it should resolve your problem. You can do the same for your site-packages folder if that's currently polluting your project structure space.
To get to the right menu:
Click File -> Settings
Navigate to Project -> Project Interpreter
Click the gear on the top right and click "More"
Select your interpreter and click the "Show paths" button on the right
Instead of clicking refresh, as many other posts suggest, click the "Add" button on the right and add your paths
There's a handy screenshot uploaded by r---------k on the updating python-skeletons post that if that helps you.
Try installing the Python package for Windows from
http://www.python.org/download/windows and point PyCharm to that
interpreter instead.
Settings -> Project -> Project Interpreter -> Gear -> Add Local
You may also need to install PyCharm's Python packaging tools (you
should see a link on the bottom of the Project Interpreter page if it
isn't installed already).
While this may not be a perfect solution depending on your workflow
because PyCharm will no longer be using Cygwin's python interpreter,
but this at least got rid of those pesky squiggly red underlines for
me.
I use Windows 10 x64, Python 3.5.1 and PyCharm Community Edition 2016.1.4
I have the same problem and sovled it by runnig PyCharm in admin mode (it is required only once).
I have a problem getting PyDev on eclipse to recognize already installed modules. Here is my detailed approach. The machine is a Mac (Snow Leopard).
In terminal the command
python --version
shows Python 2.6.6.
import unidecode
and
from unidecode import unidecode
work both fine!
I installed PyDev in Eclipse and went to configured the python interpreter (Auto Config). I selected all the proposed packages and hit Apply and Ok.
But eclipse keeps complaining
Traceback (most recent call last):
File "/Users/me/Documents/workspace/myproject/python/pythontest.py", line 12, in <module>
from unidecode import unidecode
ImportError: No module named unidecode
The python file looks like this
#!/usr/bin/env python
# encoding: utf-8
import sys
import os
from unidecode import unidecode
def main():
print unidecode(u"Ă…got Aakra")
if __name__ == '__main__':
main()
When I remove the first line in the script
#!/usr/bin/env python
it results into the same error.
Does someone know where the problem lies?
This is the solution to my problem:
Find out the path to the folder ../site-packages/ of your corresponding python version. ( For me it was /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ for python 2.6 on my Mac with Snoe Leopard.)
Open eclipse preferences and go to PyDev -> Interpreter - Python.
On the left side of the lower box, click on New Folder.
Add the navigate to ../site-packages/ of your corresponding python version.
Hit open.
Hit Apply.
Hit Ok.
And you should be good to go. =)
Thanks #all particionts, who provided hints into the right direction in the comments.
I ran into the same problem just today. I am using pydev and had a working project with a number of sub-packages. Suddenly after having created a new module I was not able to use this module in a different package. The puzzling feature was that I could use another module in the same sub-package...
Finally after
eclipse restart
remove/add python interpreter and all site-packages
annoyed head-scratching
I deleted all compiled classes with the following script:
import os
def clean_folder(folder):
for file in os.listdir(folder):
path = os.path.join(folder,file)
if os.path.isdir(path):
clean_folder(path)
if '.pyc' == file[-4:]:
print 'deleting: ' + str(path)
os.remove(path)
if __name__ == '__main__':
folder = 'YOUR_PROJECT_SRC_PATH'
clean_folder(folder)
and finally I can do 'actual' work :)
Hope it helps somebody...
You can simply add the module to the pydev path. Go to project properties (from the context menu) -> PyDev -> PYTHONPATH -> External Libraries. Depending on whether the module is in a source folder or a zip/egg file, select either Add source folder or Add zip/jar/egg. Navigate to the site-packages directory and point to the relevant file or folder (mine is: /usr/local/lib/pythonx.x/site-packages)
Try preferences > pydev > interpreter - python and removing and re-adding the python interpreter (make sure you know the path to it before you delete it), when you re-add it tick all the boxes.
When Eclipse gets 'lost' with respect to what packages exists on your system or in your project, from the context menu of your project, choose 'Properties' menu item, then the 'PyDev - PYTHONPATH' item in the treeview on the left of the dialog, then the 'Force restore internal info' button. Seemingly, PyDev keeps a computed cache of the info and when for any reason the cache becomes incoherent, you can force PyDev to recompute.
In my case I was not getting this error before compiling, but when I compile I got the error ImportError: No module named myant.core. I tried to add the files from PyDev-PYTHONPATH, but again I got the same error. Then I realized that I actually do not have to add the path exactly to the folder where my .py files are located. Infact I have to add the folder where myant.core is located. After doing this I did a restart when I recompiled my project again, the problem was fixed. I would share that I have:
Python 2.7 Eclipse kepler 4.3, PyDev 3.9.2 and on my ubuntu 14.04
.py files location:/${PROJECT_DIR_NAME}/src/myant/core, therefore I added /${PROJECT_DIR_NAME}/src
#Aufwind your answer above helped but didn't solve for me.
Find the path to the folder ../site-packages/ ....
Open eclipse preferences and go to PyDev -> Interpreter - Python.
On the left side of the lower box, click on New Folder.
---> here I departed from your instructions. I added the egg for the module that wasn't being recognized. Adding the site-packages folder didn't fix it.
Hit open.
Hit Apply.
Hit Ok.
And then I was good to go. =)
Open eclipse window -> preferences and go to PyDev -> Interpreter.
click on 'Check if interpreters are synchronized with environment'
This did it for me. No Eclipse restart was required.
I fixed this problem by going to the project properties -> PyDev Django
and setting the Django settings module.
For Oxygen 2 (I think it worked on earlier versions, too)...
Right click on project folder and select "Properties"
Select "PyDev - Interpreter/Grammar"
Click on "Click here to configure an interpreter not listed"
Select any existing interpreter from the top list of configured interpreters
A "Selection Needed" dialog should appear where you must select one or more interpreters to restore. Check all that apply
Click "Ok" and PyDev will rescan, and I assume, rebuild some internal view of your site-packages
Click "Apply and Close" to close all dialogs
To make the import error markup disappear in my code editor, I need to type a space after the offending import then save the change. The import error then disappears because PyDev can now find the offending import module.
Suppose your eternal module is in /.
Launch Eclipse and go to the project option. Select "PyDev-PYTHONPATH"
and on the right you will see a tabbed window. Select External Libraries there.
Click on Add Source Folder and select your library from the above path.
I'm doing my VERY first project using python/django/eclipse/pydev following this guide
http://docs.djangoproject.com/en/dev/intro/tutorial01/
My only addition is the use of Eclipse/pydev.
I'm getting many errors related to "Unresolved imports". I can remove the errors using "remove error markers" and my site runs perfect (I can browse it) but I want to get rid definitively of this problem since errors pop up again after I removed them.
Any ideas?
EDIT
Using Ubuntu 9.1
Check your pythonpath. You need to include the parent directory of django, usually Lib/site-packages.
I'm on Mac OS X, but all I had to do was to add:
/Library/Python/2.6/site-packages
to my System PYTHONPATH (Found in: Preferences > Pydev > Interpreter - Python)
The equivalent for Ubuntu 10.04 would be:
/usr/lib/pymodules/python2.6
I'm guessing that the equivalent for Ubuntu 9.x could be:
/usr/lib/python2.6/site-packages
If it isn't and you're tired of looking, just upgrade to Ubuntu 10.04 and you should be fine.
I was able to get rid of the import errors executing this cmd
sudo ln -s /usr/lib/pymodules/ /usr/lib/python2.6/pymodules
I was lucky, testing different things I could resolve it but I'm not sure why I have to do this and how I could avoid doing it.
"Unresolved imports" occur when Eclipse/Pydev does not know what you want to import. Check your Pydev settings in the Eclipse preferences > Interpreter Python. Your site-packages folder and things you want to import should be there in the Pythonpath.
Also see http://pydev.org/manual_101_interpreter.html
Even if Lib/site-packages is added to the PYTHONPATH, this problem may happen when using modules from egg packages installed using easy_install. The problem with those, and that might actually depend on the easy_install version, is that by default they don't get installed directly inside Lib/site-packages but rather under a folder containing the full package name and having the .egg suffix. For example: Lib/site-packages/django_celery-3.0.23-py2.7.egg
Each module coming from packages installed as above needs an individual entry in PYTHONPATH. If the packages are installed after PyDev has been installed on the system, the system PYTHONPATH needs to be updated in PyDev. That is done automatically by going to Window -> Preferences -> PyDev -> Select your intepreter -> in the python interpreters panel remove and re-add your current python interpreter (usually, this should be the python executable from the system). Then a PyDev restart (File -> Restart) should solve the "Unresolved import" errors.
If you are facing problem of unused imports then I must say use Eclipse as a IDE as it is providing functionality to remove unused imports by pressing keys ctr+shift+O. Or In Eclipse there is plugin also available which is doing the same thing automatically when you save your code.You can get that plugin from eclipse plugin site easily and free of cost.
In my case of the modules were dependent on setuptools-14.3.1 , which was causing all these problems. After installation of setuptools-14.3.1 rest of the modules automatically resolved.
I was having a single import error when working in PyDEV in eclipse.
I was importing it like
from xyz_module import abc
So I clicked "Ctl + 1" and "select Unresolved import error" in eclipse and it created a class
file in a python file.
It turned out that I had created an application called "xyz_module" and a "xyz_module.py" file (with the same name that is) and this was causing an import error. I changed the python file to a new name and this resolved the error.
I had the same error and none of the answers worked for me as there was no PYTHONPATH options under Window -> Preferences -> PyDev -> Python.
Instead I added PYTHONPATH setting in the menu:
Project -> PyDev-PYTHONPATH -> External Libraries -> Add Source folder
I added the path of site-packages like
/home/Documents/hcx/venv/lib/python3.5/site-packages
Now PyDev stopped complaining.