TensorFlow with Eclipse - python

I'm trying to run the TensorFlow Python examples for with Eclipse Mars for Mac OS X, but I'm getting the following error:
Unresolved import: tensorflow.python.platform
The error is raised on the 3rd line:
from __future__ import absolute_import
from __future__ import print_function
import tensorflow.python.platform
I'm new to Python and TensorFlow. I'm using PyDev for Eclipse. I read somewhere that I can add code to the "External Libraries" folder but I'm not sure where the TensorFlow library is.
I installed TensorFlow following the installation directions on the TensorFlow website.
What am I missing?

It sounds like you are running into a problem with your Python environment. The easiest way to deal with this is to follow these steps:
Install TensorFlow into a virtualenv, by following the instructions here. This avoids the need to acquire root privileges, and makes it easier to experiment with different versions of TensorFlow. (It also avoids conflicts with other system-installed versions of different libraries.)
Set up PyDev to use your new virtualenv, by following step 5 onwards in this guide. This involves setting up a new "interpreter" whose library will be the set of libraries in the virtualenv. You may need to recreate your Eclipse project to use this interpreter.

install tensorflow.
in eclipse , assume you have pydev installed, go to preferences>pydev>python interpreter.
in the libraries tab add the path to the lib folder of your tensorflow lib folder.
here is screenshot:

I also had import issues. I fixed it by creating a new project and specifying interpreter as ~/tensorflow/lib/python2.7
Eclipse seems to then point to the right interpreter and offers to import other relevant files - result is similar to answer above.
The answer from #mrry above was helpful - only the link to the 5 step guide seems to be unavailable.
Hope this helps!

Related

Why does importing Pytorch in Sublime Text cause a ModuleNotFoundError?

The command 'import torch' causes the build error: 'ModuleNotFoundError: No module named 'torch''.
But when I run the command in the terminal, pytorch works just fine (Python 3.7.X).
Are you using a venvin the project you are right now? If that is so, then you need to install torch in that venv, as it has been created just for the project, so it has not got any extra modules like that one.
Take a look at this. And make sure that the module is in the environment your project is!
In Pycharm for example, whenever you create a new project with a new venv(virtual environment), you need to add to your project settings->interpreter settings the module manually, so it can be imported. Because it may be installed in your system, but not in that venvspecifically, which will look in there!
try this
link
it might help.
Also Faced similar issue in Windows 10 with Anaconda installed. Installed pytorch package using conda install command which I found here: http://pytorch.org/
The usual import from command-line worked for my environment(torch):

How to use tensorflow in pycharm?

I have installed tensorflow on my Ubuntu, I can import it from shell but I can't from pycharm. Here is my screen :
How can I solve this?
You should name your project differently: now you are trying to import package tensorflow (your project) and use it inside of it.
Try to rename your working directory to tensorflow_test or something different than tensorflow.
You have to change the python interpreter that PyCharm is using.
Go to options->project->project interpreter and select the correct one, most likely a virtualenv you created, where you installed tensorflow instead of the default.

Importing OpenCV with python 2.7 in Virtualenv and PyCharm

I am struggling with installing opencv for python 2.7.11 on OSX for almost three days now.
After some failures, I accomplished a first success by following the instructions here. So my basic setup is python 2.7.11 running from ~/.virtualenvs/cv_env/bin/python and I have a cv2.so located in ~/.virtualenvs/cv/lib/python2.7/site-packages/.
So good so far. Using source ~/.virtualenvs/cv_env/bin/activate, I can activate the virtualenv and than use import cv2. For some reasons, this does not work always. From time to time, I have to deactivate first and than reactivate (any guesses?).
Next, I wanted to use opencv in PyCharm. Under "preferences - Project interpreter", I selected the virtualenv interpreter and this is also working. I can import other moduals like numpy and pandas (previously installed into the vortualenv using pip). But for some reasons, I am not able to import opencv (import cv2). It always gives me
ImportError: No module named cv2
So my question is, why I am able to import opencv in terminal (at least sometimes) but not in PyCharm. Any ideas are welcomed.
Best,
Fabian
Your cv2.so located in a different directory. And you activating from another directory. I mean cv_env and cv.

Getting PyCharm to import sklearn

Beginner here.
I’m trying to use sklearn in pycharm. When importing sklearn I get an error that reads “Import error: No module named sklearn”
The project interpreter in pycharm is set to 2.7.10 (/anaconda/bin/python.app), which should be the right one.
Under default preferenes, project interpreter, I see all of anacondas packages. I've double clicked and installed the packages scikit learn and sklearn. I still receive the “Import error: No module named sklearn”
Does anyone know how to solve this problem?
To make sure you have Scikit-learn package installed on your PyCharm IDE, go to File Menu>Settings and search for Interpreter. Select Project Interpreter, and if you dont see Scikit-learn in the list of packages, click the + sign on the right end. It brings us another window with a search bar, where you can type 'Scikit-learn' and install (see screenshots). I hope this helps.
Screenshots:
,
please notice that, in the packages search 'Scikit-learn', instead 'sklearn'
go to terminal- type python -m pip install scikit-learn
then hit enter.
give it some seconds. It will be done.
Sample Image
Double check your python interpreter. Check whether you have select correct interpreter at the first when you create the project.
Or else you can check your interpreter from the project view under External Libraries.
In your case if you didn't select 2.7.10 (/anaconda/bin/python.app) as your interpreter for the project at the beginning still the program give the same error Import error: No module named sklearn.
Same error occurs to me i have fixed by selecting File Menu-> Default Settings-> Project Interpreter -> Press + button and type 'sklearn' Press install button. Installation will be done in 10 to 20 seconds.
If issue not resolved please check you PyCharm Interpreter path. Sometimes your machine have Python 2.7 and Python 3.6 both installed and there may be some conflict by choosing one.
I had exactly the same problem. I'm using PyCharm with Anaconda3 & Python 3.7, and I've installed other packages into/via PyCharms just fine (such as numpy, scipy, and others). But although scikit-learn (which contains sklearn, that was initially confusing) seems fully installed on my system, including "import sklearn" working outside of PyCharm, I could not get the "import sklearn" to succeed inside PyCharm.
I finally got a python-expert friend to help me. He verified everything was correctly installed on my system and verified that PyCharm was somehow messing up.
We finally determined that the venv (virtual environment) was not including scikit-learn (sklearn) even though I had imported it properly into the Project Interpreter in PyCharms.
Solution: Delete and recreate the VENV, specifically ticking the box Inherit Global Site Packages
See here: https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html
for how to create a new virtual environment and get to that parameter.
SOLVED:
reinstalled Python 3.7.9 (not the latet)
installed numpy 1.17.5 (not the latest)
installed scikit-learn (latest)
sklearn works now!
For Mac OS:
PyCharm --> Preferences --> Project Interpreter --> Double Click on pip (a new window will open with search option) --> mention 'Scikit-learn' on the search bar --> Install Packages --> Once installed, close that new window --> OK on the existing window
and you are done.

Python: Unresolved import error for sqlite3 in PyDev in Eclipse

import sqlite3 generates:
Unused import: sqlite3
Unresolved import: sqlite3
sqlite3 Found at: DatabaseTests
import sqlite3
However, this works perfectly in the terminal when using the python command-line.
I am running on a Mac Mountain Lion, with the default installation of Python. I am using PyDev in Eclipse Indigo.
This is a very old thread but I don't see the solution I found for this problem so I'll post it in hopes that somebody sees this and can then solve the problem:
you need to add 'sqlite3' (without the quotatios) in the 'forced builtins' tab in Window>Preferences>PyDev>Python Interpreter
I fixed this by adding _sqlite3 (note the underscore) to the Forced Built-ins in Window>Preferences>PyDev>Interpreters>Python Interpreter.
I have the same development environment and suffered from the same issue. I have resolved it by
switching to the MacPorts Python,
by only using packages that I install from that project
and by setting the default Python interpreter on Eclipse-Pydev to be the MacPorts executable
This works perfectly for me, with the one hitch that I still sometimes get an Unresolved import warning, but if the package is installed, my script still runs.
Looks like the project references do not have the site-package path added. Try adding the path to sqlite3 (/usr/lib/python2.7/sqlite3/ or the path installed to which you can get from python shell) to project references from Project -> Properties -> Pydev-PYTHOPATH -> External libraries.
I had a similar problem with other imports (simplejson and matplotlib).
I'm working on Ubuntu and the problems with the imports started after upgrading from Ubuntu 11.10 to 12.04 (which also upgraded the python version and the eclipse).
My steps for solving the problem were:
In the terminal, do 'import sys' then 'print sys.executable'. This gives the path to the current interpreter.
In Eclipse - Window->preferences->PyDev->interpreter-python. Remove the old path and add the path retrieved in stage 1.
In the problematic project go to Project->properties->PyDev-PYHTONPATH, the external libraries tab remove old paths and add the correct ones (on Ubuntu one can find it via the synaptic manager, e.g. for simplejson go to the synaptic manager, type simplejson in the search box, mark the right result right-click and choose properties from the menu then choose the 'installed files' tab to see the path for the installed files.
I hope someone will find it useful.

Categories