PyDev doesn't autocomplete for some modules (numpy, matplotlib at least) - python

This is similar, but not this question Code-Completion for e.g. Numpy, SciPy or Matplotlib does not work in Eclipse PyDev
My problem isn't that PyDev can't resolve the variables as their specific type, I can't even get it to look into the numpy module for the functions. For example
import numpy as np
np.<ctrl+space>
gives me nothing. These modules are in my list of forced builtins.
Autocomplete does work for many other modules (including Qt/qwt, serial, struct) and the programs run fine. However, every time I use np.something eclipse thinks it is an error(red line under it). Does this "just work" for everyone else?
Edit (additional info):
There are errors in my error log. However, they are about Java not having permissions to run pylint and complaints about invalid encoding. I am running Eclipse 3.8.1 with python 2.7 on Ubuntu 13.04. Historically, I develop python in Spyder, so whatever I am missing likely has to do with Elipse nuances.

It should 'just work' for you. Can you check if 'numpy' is on the 'forced builtins' list (in your interpreter configuration -- it should be added automatically, but it's possible it's not there. See: http://pydev.org/manual_101_interpreter.html for details on it).
If it is and you still have an issue, please check if you have some error in your error log -- see: http://pydev.org/faq.html#PyDevFAQ-HowdoIReportaBUG%3F for details on getting it.

Related

importing dlls with pythonnet in spyder

I have a python package that acts like a wrapper for a .dll written in C#. The binary is imported into python by the pythonnet package. Thus, the user can access the functionality of the so called cs_backend.dll conveniently from the python side. The import looks as follows:
import clr as __clr
import System as __System
__clr.AddReference(PATH_TO_CS_BACKEND + "\\cs_backend")
import cs_backend as __csb # exception thrown here
However, it seems that python can't import the .dll as I get a ModuleNotFoundError: No module named 'cs_backend'.
The odd thing is that this error only occures when running the code from Spyder. Executing exactly the same code from Visual Studio Code works perfectly fine.
Do you have any idea what the problem could be?
system specifications
os: windows 10
.net framework v4.5.1
python 3.8.5
spyder 4.2.1
Edit:
I have found a github issue on the pythonnet repository that describes a similar (although not quite the same) problem. However, since it has been open for about 3 years, it seems that there is little to no progress on that.
Edit 2:
There is a similar question here on stack overflow. The solution was to install a newer .NET Framework. This is not my problem since with any IDE other than Spyder the code works just fine. Thus, I guess that this is mainly a Spyder issue.
Currently, it seems that there is neither a solution nor an effort to resolve this problem.
It looks like the problem is caused by the IPython console integrated in Spyder.
A simple workaround is to execute the python script from the system console.
In Spyder this can be done by going to Run - Configuration per file - Execute in external system console.
With the new configuration it is at least possible to run the script.

How to make VS Code editor aware belonging imported packages in python?

I use VS Code to write and test python scripts.
Is it possible to make the editor aware of imported modules
to avoid problems listed like
Module 'numpy' has no 'divmod' member
You would update the Python interpreter settings according to where modules have been installed. (bottom right of VS Code)
The IDE being used isn't really relevant because you could invoke /path/to/bin/python, start a REPL, import the same module, and get the same error
Regarding, "numpy has no ... member", based on searching, that is a PyLint issue, not an import issue
How do I get PyLint to recognize numpy members?

Python's matplotlib import

On my working PC (Windows7, no internet connection) there are two Pythons: one is the main (C:\Python36-32) with IDLE. Another - freshly installed Anaconda (C:\ProgramData\Anaconda3) - just for scipy and matplotlib (IT guy thought it is the best option).
So, matplotlib works only if I run my scripts from cmd. But it is not comfortable. I prefer IDLE or any other modern environment.
But if I try use matplotlib in IDLE - I got an "No module named 'matplotlib'". I tried to edit sys.path and run:
sys.path.append("C:\\ProgramData\\Anaconda3\\Lib\\site-packages").
It helps a little bit - I got new error "No module named 'matplotlib._path'". So, it looks like IDLE knows what is matplotlib now, but doesn't know it's functions.
Is there any way to connect IDLE with Anaconda's libraries? Maybe to append paths recursively?
It's probably not a good idea to mix the python distributions through the system path.
Python should ship with IDLE. So you can use the IDLE from the Anaconda distribution,
C:\ProgramData\Anaconda3>python.exe Lib\idlelib\idle.py
Also note that Anaconda should also provide Spyder. This might be a nicer IDE.

The PIL library import fails

Being a complete begginer in python, I decided to install the python interpreter 3.4.4, and also PyDev plugin for eclipse IDE. I am also using windows 10.
I have encountered a problem regarding certain imports, namely : from PIL import Image, ImageTk, which is apparently an unresolved import.
I have looked at certain questions which were similar to my situation, but most of them gave a solution like installing packaged from the linux apt-get. Here are some topics I visited :
Uninstalling and reinstalling Pillow and pip,
Installing pillow-imaging-tk on Ubuntu,
This topic which left me very confused,
This one seemed helpful, but is on Unix OS again
So please, could someone explain to me why I am seeing this error, and how could I correct it if I absolutely want to use Eclipse, Pydev, windows 10 and Python 3.
Found the solution, here's what I did:
Set the PYTHONPATH like it is shown in this article, make sure python.exe is accessible via cmd,
Via cmd, type pip install pillow. Alternatively, you can enter the same command from Windows+R,
(Not sure if relevant step) Via eclipse, Windows->Preferences->PyDev->PythonInterpreterremove your interpreter to re-add it,
Restart eclipse.
For Python import problems in PyDev, the project web site has a page on interpreter configuration that is a good place to start. I recently had a similar problem that I solved by adding a module to the forced builtins tab.

How do I handle an UnresolvedImport Eclipse (Python)

When I write import MySQLdb in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this?
How can I help Eclipse know that MySQLdb is there?
It sounds like MySQLdb is somewhere on your sys.path, but not on your Eclipse project's PYTHONPATH; in other words, Eclipse thinks you're going to get an import error at runtime because you haven't fully configured it. Google seems to say that you can alter this setting in Window->Preferences->Preferences->PyDev->Python Interpreter to include the path to your MySQLdb module.
For some help figuring out where MySQLdb might be living on your system:
Open an interactive interpreter,
import MySQLdb
If that succeeds, you can get a hint from: print MySQLdb.__file__; it may be the __init__ file in the package that you need to point the path at.
cdleary above provided the reason two years ago, but this may be easier. Basically, one reinstalls the interpreter.
Select Window - > Preferences -> PyDev -> Interpreter - Python
Select the python interpreter in the upper pane
Click on Remove
Click on Auto Config
Agree to everything.
This works on Fedora 17 using the Eclipse 4.2.0 that came with the package management.
Fixed this by doing two things:
1) Added MySQLdb egg to the PYTHONPATH under Window->Preferences->Preferences->PyDev->Python Interpreter.
C:\Python26\Lib\site-packages\MySQL_python-1.2.3c1-py2.6-win32.egg
2) Close and re-open the .py file that had the red x.
Adding the egg works, but the error remains. The solution for that error can be found by adding
##UnresolvedImport
To the import statement, as in:
import web ##UnresolvedImport
Source: http://klaith.wordpress.com/2009/06/12/pydev-unresolved-import-errors/
I once had a similar problem on Windows (never encountered this on Linux though) and I discovered that I had to include the .egg directory of my library to my PYTHONPATH.
For example my PYTHONPATH (Pydev/Interpreter - Python/Libraries) included:
C:\Python26\Lib\site-packages
and I had to add:
C:\Python26\Lib\site-packages\jinja2-2.2.1-py2.6.egg
to use jinja.
This surely works I just tried it with Pmw package. Unzip package in site-packages. Then remove python interpreter from eclipse and then add it again. Your import errors shall go away. also you may want add module to forced builtins. See How do I fix PyDev "Undefined variable from import" errors? and http://pydev.org/manual_101_interpreter.html
I had a similar issue and the following is what I did to solve my issue. I have a Windows 8 Machine, Python 2.7 installed and running my stuff through eclipse.
Some Background:
When I did an easy install it tries to install MySQL-python 1.2.5 which failed with an error: Unable to find vcvarsall.bat. I did an easy_install of pip and tried the pip install which also failed with a similar error. They both reference vcvarsall.bat which is something to do with visual studio, since I don't have visual studio on my machine, it left me looking for a different solution, which I share below.
The Solution:
Reinstall python 2.7.8 from 2.7.8 from https://www.python.org/download this will add any missing registry settings, which is required by the next install.
Install 1.2.4 from http://pypi.python.org/pypi/MySQL-python/1.2.4
After I did both of those installs, I reopened eclipse and got a prompt to update the paths of eclipse which I accepted, after that I was able to query my MySQL db.
import MySQLdb
If this code show error like this:
Unresolved import: MySQLdb
you should add D:\Python27\Lib\site-packages\MySQLdb to your sys.path.
D:\Python27\Lib\site-packages\MySQLdb is this location where you install MySQLdb in your computer disk. After this step, the error will disappear.

Categories

Resources