I am using PyDev/Eclipse for several monthes and I get ever and ever the same bugs with imports:
PyDev underline in red an import and say Unresolved import xxx ; Found at yyy. When I click on yyy eclispe find and open the implementation of the module.
(PyDev just inform me that it can't find the module xxx and in the same message that it can find it !)
The module xxx is in the PYTHONPATH of eclipse. When I "explore" the interpreter of the project, I can find it without any problems.
When I try to execute (from eclipse), I don't get any error and it works fine.
Sometimes, the error message will stay for several days and will disappear. Sometimes, it won't. I've tried to refresh the projects but it has not impact on that.
Somtimes, it works well on a project and I can use autocompletion and it don't work in another project (same interpreter) ...
I just can't understand what is happenning ?
So far, I have ignored these bugs because everything was fully fonctionnal but sometimes, it is a bit disturbing to have red markers "errors" when you are working.
Did you find a way to avoid these bugs in PyDev ? Is it "normal" ? Is there a way to force PyDev to "refresh" ?
Thank you.
References :
python 2.4.4 (built from sources)
PyDev v 1.6.0 2010071813
This can happen if new modules are not cached by PyDev. For example, on my new laptop I first set up PyDev/Eclipse and later installed the Django package. That's why Django imports were marked as unresolved. You can refresh it using Pydev > Interpreter - Python > Libraries > Apply. Select the interpreter you want to "restore" (they could have chosen a better word) and click OK. PyDev will then reparse all installed modules.
I'm using the nightly version of PyDev, but any 1.6.x version should work correctly. If that doesn't help, remove the interpreter configure and create a new one.
You can try refreshing your PYTHONPATH in Preferences > Pydev > Interpreter - Python and selecting AutoConfig for your interpreter, then manually choosing the libraries for your PYTHONPATH.
This is pretty radical solution though. Making an insignificant change (like adding a space) and saving file should work in most cases. If not, you can also try temporary delete and then re-add the imports in file that is causing problems.
Just in case anyone else runs into this thread but above answers don't solve the issue, make sure that your script does not have the same name as the library that you are trying to import.
Related
I'm using Pycharm (2019.1.2 x64) from quite a while and I never changed the standard settings.
The standard settings diplay keywords (def, class, if) in orange, pressing tab will auto complete the keyword and add a space, build-in functions (sum(), map(), print()) are displayed in purple and pressing tab will auto complete the function name, add brackets and move the cursor inside the brackets.
This is the desired behavior and it's what I get when opening any project in Pycharm except one.
In a single project this behavior suddently changed, I did nothing but writing and running code.
I noticed because tab suddently started indenting by 8 spaces instead of 4, no big deal I changed it back to 4 in the bottom of the IDE, but I also noticed that print was seen as a keyword (so orange with no brackets) instead as a built-in function, just like in Python2 (I never used it and the project's interpreter was Python 3.7). from __future__ import print_function would turn print into a function again but it's Python2 stuff.
I fixed it by creating a new virtual environment and setting up the interpreter again, so my question is:
What causes this unexpected behavior?
I would like to avoid this when working on my most "serious" projects. Thanks all.
NEW ANSWER
Well, this happened to me just yesterday while I was working on my tkinter project. It showed tkinter in from tkinter import * "Module not supported in Python 2.7", even though I was using Python 3.8.
Solution One
To fix this issue, I just simply went to
File > Settings > Appearance and Behavior > System Settings > Updates
And updated PyCharm to the latest one. It worked for me.
Solution Two
Another method I found out is to go to
Press Shift Key Twice > Typing "Restore Default Settings"
Doing this will also restore all the settings partially and fixes the problem for me.
Why Did This Happen?
This is due to a bug in older versions of PyCharm (probably). I got this bug while testing some Google API that was in Python 2.7. If you ever opened a project containing Python 2.7 Interpreter and opened another project that is in Python 3 and above, PyCharm thinks that the code that is written is in Python 2.7 and just formats the guide according to it. Some example can be "f" in print(f"{some_variable_here}") being shown as "Not Supported In Python 2.7". This is just my theory I may be completely wrong here.
OLD ANSWER
Are You Using macOS? if yes, macOS comes with Python 2 preinstalled. So probably this may be a bug. I suggest going to the bottom right corner and there would be written "Python (Version)". If it is something other than 3 or above (like 2), click on it, and go to "Interpreter Settings" and there, from the drop down menu, select the other Python interpreter that is installed on your device.
If this does not work, then it may be a theme bug, or something to do with PyCharm itself (probably). Reinstalling and clearing the cache should probably work.
I remember autocompletion to be working for me on PyCharm some time ago, but I just noticed that is no longer is. It doesn't work for basic python syntax as well as any libraries.
I've tried using the "Invalidate Caches and Restart" option in the File menu of PyCharm. I've also made sure that the Project Interpreter is using the Python in the venv of the project created by PyCharm. I've tried a handful of other things but these two are the most common solutions I've encountered and nothing is working. Note that hitting Ctr-Space anywhere just gives me a "No suggestions" message (not sure if this is relevant but thought I'd mention it).
Any ideas? Any help or ideas at all are appreciated.
I am using a mac, I set up all the external libraries through PYTHONPATH, I tried setting it through Pydev interpreter as well.
It simply does not work. The odd thing is that pydev is highlighting the syntax as error, but when I run the code, it works perfectly. I am out of ideas of what the problem might be. I used to program in java with eclipse, and once you set up the external libraries all the highlighting and autocompletion is working. With pydev I have no idea what is wrong.
Here is the image of the wrong highlighting:
There's a similar problem with importing wxPython with PyDev Aptana Studio 3. Based on the research I did then, PyDev has a hard time validating new imports when a module has recently been downloaded. This means that there is just a bug in PyDev, so it would be a good idea to report it.
As for the solution, from what I've found a useful link with a ton of answers that should fix your problem. There's some detailed instructions but the fix that I found was towards the bottom someone said to try wx = wx after importing wx. This worked for me, but may not work for you so here is the link if you need a better answer:
Undefined variable from import when using wxPython in pydev
I have had trouble setting up the pycharm ide on my macosx10.7 with python3..
I have scoured every resource available and tried hundreds of approaches, at this point I must accept my incompetence and seek help via this channel.
In my research, I notice a lack of ground-up explanations on python integration into macosx and how to configure pycharm to import modules, run code within the editor, etc. If i ever solve this I will make a very detailed tutorial.
I have imported python3 successfully, it looks like it is linked appropriately from /sys/lib/frameworks to /usr/lib ...etc -- version control is working just fine.
I think my issue is either in setting environmental variables (tried the program to fix this and tried macports) and in the script needed to execute. it will catch errors throughout but final product does not run in python and returns printout of :
/Library/Frameworks/Python.framework/Versions/3.2/bin/python3.2 /Users/anon/Desktop/pythonpractice/Py_Ex/classes.py
Process finished with exit code 0
i really need to get this configuration sound for my python programming class. please help (I've been through every line of pycharm website) .. preferably is there a way to map it via terminal? thanks for anyone who took the time to read this.
Summary of the discussion above:
Python 3.2.2 installation was broken on this Mac, installing ActiveState Python 3.2.2 from scratch and configuring it in PyCharm has fixed the problem.
Python path to be used in PyCharm settings: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3
Incompatible third-party plug-ins may break PyCharm, uninstall/disable them in Preferences | Plugins.
Ensure the latest PyCharm version is installed.
User's code depends on the graphics.py module which was not in the project or in the PYTHONPATH. Putting it into the project has solved the problem.
Most likely the wrong Run/Debug configuration was used in PyCharm, the easiest way to run or debug such scripts is by using the editor context menu Run and Debug actions. PyCharm creates the configuration automatically and debugging works fine as shown of the screenshot:
If one wants to configure and debug it, he can use the code.zip file to get started.
Sorry for the comments mess above, but it was not possible to move it into chat as user had only 1 reputation point, hence not able to use the chat feature of StackOverflow.
I'm writing a crossplatform python script on windows using Eclipse with the Pydev plugin. The script makes use of the os.symlink() and os.readlink() methods if the current platform isn't NT.
Since the os.symlink() and os.readlink() methods aren't available on the Windows platform Pydev flags them as undefined variables--like so:
Question:
Is there a way to ignore specific undefined variable name errors without modifying my source file?
edit: I found a way to ignore undefined variable errors from this answer on stackoverflow.
I'll leave the question open in case there is a way to solve this using project file or Pydev setting.
I use pydev + pylint.
With pylint you can add which messages to ignore in the Preferences>Pydev>Pylint>"Aggruments to pass to pylint" section.
--disable-msg=W0232,F0401
You can ignore messages in-line as well with comments:
os.symlink(target, symlink) # IGNORE:<MessageID>
Mouse-over the "x" where the line numbers are to see the message id.
I suspect pydev may have better, specific solutions, but what about just putting some code at the start of your program, such as:
if not hasattr(os, 'symlink'): os.symlink = None
Yeah, it's a hack, but, unless pydev does have specialized solutions (unfortunately I don't know of any, but then I'm no pydev expert;-), may be better than nothing...
I noticed PyDev doesn't recognize ZeroMQ constants so I struggled with the same problem.
I found PyDev has a settings option in Preferences > PyDev > Code Editor > Code Analysis : Undefined-tab. Just write symlink and readlink there (comma separated) to remove the errors.
Still not optimal, but good enough for now.