PyDev unresolved import with sklearn - python

I'm running PyDev in Eclipse 4.2 on Mountain Lion. I installed the SciPy Superpack, and can use all the packages -- including Scikit-learn and MatPlotLib -- in the Python interpreter and through IPython. However, when I try to import them in PyDev I get an 'Unresolved import' error.
I installed Python 2.7.3 from Python.org, and verified that PyDev is pointing to the correct interpreter. I also attempted to add the sklearn and matplotlib directories (verified via the path from sklearn.__file__) to the System PYTHONPATH in the PyDev settings. This didn't resolve the issue.
Any idea what else I should try?

From your comment examples, seems the path you are using is at the wrong depth.
Change from:
/Library/Python/2.7/site-packages/scikit_learn-0.12_git-py2.7-macosx-10.8-intel‌​.egg/sklearn
To:
/Library/Python/2.7/site-packages/scikit_learn-0.12_git-py2.7-macosx-10.8-intel‌​.egg
It wasn't able to find the package level name because you were specifying beneath it. Normally a python interpreter will resolve all the eggs by simply existing insite the site-packages, from the `.pth' file references that get placed there. But I think pyDev will need explicit adding of those eggs to the PYTHONPATH.

Related

import sklearn not working in PyCharm

I installed numpy, scipy and scikit-learn using pip on mac os. However in PyCharm, all imports work except when i try importing sklearn. I tried doing it in the Python shell and it worked fine. Any ideas as to what is causing this?
Also, not sure if it is relevant, but i installed scikit-learn last.
The error I receive is unresolved reference
I managed to figure it out, i had to go to the project interpreter and change the python distribution as it had defaulted the OS installed Python rather than my own installed distribution.
This worked for me:
In my PyCharm Community Edition 5.0.4, Preference -> Project Interpreter -> check whether sklearn package is installed for the current project interpreter, if not, install it.
PyCharm January 2020 Build
Click on File-> Settings
From the Settings Dialog-> Projects-> Your Project
Click on (+) on right side and type search for sklearn
Install it and you are good to go
If you are behind a proxy then first set proxy to AutoDetect

Can't get import to be recognized - jsonpickle

I am using PyDev via eclipse and have used easy_install to get jsonpickle. No matter what I do I can't seem to get the import to work.
What I have tried thus far:
I have removed it from easy_install.pth and deleted the egg and installed again.
Add my python lib, dll, etc folders to a PYTHONPATH system variable
Restarted eclipse
Other imports are working fine. Not sure what I am doing wrong?
EDIT:
Sorry should have included OS / Python version.
OS: Windows 7
Python: 2.7
Any suggestions greatly appreciated
OS and python version?
Please use pip. Always.
pydev seems to ignore your package. It should be in /usr/share/pythonX.Y/site-packages/jsonpickle, or, if on Windows, c:\pythonxx[...].
If using Linux, please try to find a distro package for jsonpickle.

UnresolvedError on importing package in eclipse

I get an Unresolved Error while importing a package (bigfloat) by import bigfloat in PyDev in eclipse. However on from bigfloat import * the error is resolved. What is the reason behind this?
I used easy_install to download and install the bigfloat package. Does it not update the python_path in the process??
I have also tried adding the library as an external library in the pythonpath properties, but I still get the same error.
Is the error being reported by the PyDev / eclipse IDE, or does it happen when you run the code?
In the first case, this is probably due to eclipse caching the information about what packages you have installed.
What you need to do is go to "Preferences -> Pydev -> Interpreter - Python" where you define the python interpreter to be used. Remove the current interpreter, and add it back in again.
This will cause eclipse to re-read all the path information and it should clear the error.

python newbie: importing numpy module in eclipse

I'm trying to run a simple python program in eclipse. This is the first time that I'm importting any module.
So I downloaded: numpy and pylab (I'm using a mac) restarted my eclipse and the red line below the
import numpy
import pylab
disappeared so I understood that the reference to that module is ok.
Problem is that I still see red line below the code and wonder why? I have to stress out that I believe numpy was already 'pre-installed' I just upgraded the version (using 1.5.1-py2.7).
Can anyone tell what should I do to run this code?
my interpreter setting on eclipse:
If you are using PyDev, you should first have to go to Preferences, then Pydev, then Interpreter Python and then Libraries to add NumPy.
Else, verify that you have NumPy installed, from the interpreter, just call from numpy import *
Edit:
Also check you already have Matplotlib installed, the error you are getting on the console points to that being the cause, you can download Matplotlib here.
I recently installed Anaconda3 and just started learning how to use Pandas and I wanted to be able to work with Pandas in Eclipse as well.
I first tried adding a reference to the site-libraries at:
C:\Anaconda3\Lib\site-packages
And it seemed to work by allowing me to import numpy and pandas. However, since I had just used conda to update everything, my Python34 interpreter seemed to fail when I tried running some code and numpy was looking for my Python35 installation. For some reason this was located at:
C:\Users\myname\AppData\Local\Programs\Python\Python35-32
However, Anacondas installed another version somewhere else. By going into:
Windows > Preferences > PyDev > Interpreters > Python Interpreter
and clicking on Quick Auto-Config it found my Anacondas version of Python35 and then I just had to figure out how to make my current project use the Python35 interpreter.
Hint: To do this, you need to go into the Project properties by opening the project and choosing File > Properties or right-click the project to choose Properties.
Simply removed the old numpy and installed version 6. located here
Another way to circumvent this problem is to use pip install numpy check how to install pip

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