Can't import tensorflow in PyCharm - python

I'm trying to import tensorflow in PyCharm, however I get an error that the module is not found.
I used pip install to install tensorflow.
Also when I look at the interpreter in PyCharm it says I have pip version 9.0.1 and the latest is 10.0.1. I have upgraded to 10.0.1 using the pip commands, and when I run pip --version it says I got 10.0.1.
I have tried both reinstalling pycharm and making new projects with no luck.

Go to Files -> Settings -> Project:projectname -> Project Interpreter
It's possible, that there is a different interpreter choosen for your project then the one you installed tensorflow in.
If you're running on linux you can check with "which pip" the path to your python distro in which you installed tensorflow.

This video explain it on a very simple way: https://www.youtube.com/watch?v=K9ypGzuP6xQ
Basically, TensorFlow is not by default installed on PyCharm virtual environment. You can do it by downloading in the Project Interpreter menu

try cleaning System Cache
On the main menu, choose File | Invalidate Caches/Restart.
The Invalidate Caches
Cleaning Cache

Related

After I installed anaconda, pip installation now gives "ssl module in Python is not available" error. How to fix this without uninstalling anaconda?

I've been enrolling in JetBrains academy for almost 2 months now to learn python core and machine learning with python. I have learned how to create new virtual environments using PyCharm IDE and use pip installation to install useful packages. At some point when I was ready to learn the Machine Learning track, it was recommended to install anaconda navigator since it provides tonnes of pre-installed packages that are helpful for machine learning tasks.
PROBLEM:
However, ever since I downloaded anaconda navigator, I could use pip installation in conda environment ONLY. In other virtual environments, the following error occurs: "...pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available".
SUGGESTED SOLUTIONS FOUND:
Some solution suggested that I should uninstall anaconda and python,
then re-install python to fix this. However, this method would defeat
my purpose of installing anaconda in the first place.
MY QUESTION:
How to fix this error without uninstalling anaconda?
Followings are my configurations:
PyCharm Community Edition 2022.1.1 on Windows 10
Python 3.9.10 running in a Virtual Environment (e.g. Virtualenv)
anaconda navigator 2.2.0
anaconda3 with openssl 1.1.1n and pyopenssl 21.0.0 modules installed
I actually got some idea from this link. The author added extra paths for anaconda folders with openssl into the python interpreter paths:
In the PyCharm IDE, I fixed the error with the following steps:
1.
Go to: Settings -> Project -> Python interpreter
2.
Click on the "gear symbol" and select "Show All...". This will navigate you to a "Python Interpreters" window.
3.
While your intended interpreter is highlighted, click on the "path symbol" which will navigate you to an "Interpreter Paths" window.
4.
Click "+" symbol to add path in the interpreter paths window.
5.
Add a new interpreter path as shown below. (Type where conda in anaconda prompt to find the full path to anaconda3 folder)
6.
In my case, I needed to restart my PyCharm IDE for the pip installation to finally work.
<my full path to anaconda3>
<my full path to anaconda3>\Scripts
<my full path to anaconda3>\Library\bin
NOTES:
I still wonder if this is the best method there is or is there a way to install the openssl directly into my virtual environment without redirecting my interpreter paths to the ones in anaconda folder.

Uninstall tensorflow 2.1.0

I am having problems with uninstalling TensorFlow.
I have a Python script that uses TensorFlow. I want it to use TensorFlow1.15, but it is currently using TensorFlow 2.1.0. I deleted TensorFlow via my cmd: pip uninstall tensorflow and pip uninstall tensorflow-gpu. When I run these commands again it says that TensorFlow is not installed. However, I can see that my script says it is using TensorFlow 2.1.0 (I added the line:print(tf.__version__) in my script). Does anyone know where this TensorFlow 2.1.0 is installed and how I can delete it from my PC?
Also you can downgrade tensorflow by this command in Pycharm terminal :
python -m pip install --user --upgrade tensorflow==1.15
It can also be used for other libraries.
This problem means that you use different pythons in your terminal and your script.
You mentioned PyCharm. By default, it creates a virtual environment for a new project. It also can use your global python. In any case, open a terminal in PyCharm (it should be in the bottom of the window or View -> Tool Windows -> Terminal or Option + F12 on Mac, Alt + F12 on Windows). From there you should run pip uninstall tensorflow. PyCharm automatically activates the correct python environment in the terminal.
From the above-provided information it is difficult to ascertain the scenario in which you are trying to uninstall.
I suggest creating a new python environment for your project using anaconda-
follow these steps -
download exe file for Anaconda website
install it.
open cmd
create new env using this command conda create -n yourenvname python=3.6
install tensorflow 1.15 by conda install tensorflow-gpu==1.15
go to pycharm select your new conda environment.(File -> setting -> project -> project interpreter - > insert path for env)
your env in windows might be in windows installation drive - > users -> anaconda3 -> envs
File ->Setting
Now you '+' button on rightmost tool bar "click" it
finally installed package
if still package is not installed or pycharm showing error then you have to remove tensorflow from base root and reinstall it

Problem installing tensorflow in virtual environment

This issue in some form has come up before, however I am having a variant of this issue.
I had python 3.8 installed. Tensorflow does not have a version for this python.
I therefore installed python 3.7 and set up a virtual environment using virtualenv.
In visual studio code I even updated the settings json "python.pythonPath": to the correct path for version 3.7 of python.
I install the correct version of tensorflow using the correct link for 3.7 on the site:
'''pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.1.0-cp37-cp37m-manylinux2010_x86_64.whl'''
But i still get the error
"ERROR: tensorflow_cpu-2.1.0-cp37-cp37m-win_amd64.whl is not a supported wheel on this platform."
When i type python -V I still get Python 3.8.1, could this mean I am not correctly using the virtual environment?
However I have now set up virtual environment using anaconda which is limited to 3.7 and it still says 3.8 when using "python -V" and i get the same error when trying to install.
You can try to either reinstall anaconda, visual studio, or type in the command "pip install --upgrade tensorflow". This should work without the link.
After creating the virtual environment you need to activate it if you haven't already. Once you do, your command line prompt should indicate that a new version of Python, in your case 3.7 is now running.
I ended up using Anaconda with Python 3.6, it seems tensorflow would not work for 3.7 on windows.

How Pycharm is related to Anaconda and Python?

I am getting an error while installing the package
pyramid-arima
I tried the following but could not resolve the issue
conda create -n pmdissue23 --yes --quiet python=3.5 numpy scipy
scikit-learn statsmodels
activate pmdissue23
pip install pyramid-arima
Output of above commands:
Requirement already satisfied: scipy>=0.9 in
/anaconda/envs/pmdissue23/lib/python3.5/site-packages (from pyramid-
arima)
Installing collected packages: Cython, pyramid-arima
changing mode of //anaconda/envs/pmdissue23/bin/cython to 755
changing mode of //anaconda/envs/pmdissue23/bin/cygdb to 755
changing mode of //anaconda/envs/pmdissue23/bin/cythonize to 755
Successfully installed Cython-0.28.1 pyramid-arima-0.6.2
Cleaning up...
But again the package is not installed correctly and pycharm asks me to download the package. This leads me to the following questions.
I am using Pycharm on windows 10 and having issues how pycharm is configured to use python. I installed python and Anaconda on my system prior to installation of Pycharm. I selected the interpreter as Anaconda when I created the first program.
Below are my questions:
Why is pycharm creating a new virtual environment for python interpreter instead of using the original installation. ( This causes me to import all the packages for each new project I create)
Should I use Anaconda or Python interpreter. I am not sure which one is the right one. Or should I have both.
I am having problems installing packages (pycharm gives me an error that my pip is not updated). However from my command line I updated the pip to the latest version. How do I connect pycharm to the latest pip.
Last question, How can I import all the data science packages to my python installation and point pycharm to read those packages instead of writing explicit import statements.
Any help would be greatly appreciated. Thanks
I reinstalled python on my machine. Updated the pip and other packages.

ImportError: No module named 'tensorflow' using anaconda + windows

Pip Installed tensor flow (CPU only... https://www.tensorflow.org/install/install_windows) in an anaconda environment, says it successfully installed but when I go to use tensor flow (with environment activated) it displays an error saying "ImportError: No module named 'tensorflow'".
However, After i installed pandas package, and it successfully runs. i ran an update to python=3.5 for the environment (because my anaconda is 2.7 version), and tried using this link https://github.com/tensorflow/tensorflow/issues/6136 for help also. Weird that other packages run but not tensor flow. Using a PC windows 10 with intel CPU and amd graphics. Any suggestions would be helpful.
First check which environment you are using right now.
If it helps open the anaconda navigator and see whether you have TensorFlow installed in the "installed" tab of that particular environment.
Check the following on jupyter noteook and see what python version you're using in that environment because the environment that you are using might have a different python version after all.
from platform import python_version
print(python_version())
If the versions are different, try removing the TensorFlow installation and reinstalling it according to your python version. environment and recreating the same environment pip install --ignore-installed --upgrade tensorflow=='version_for_your_requirement"
If the situation is still there, https://www.youtube.com/watch?v=tPq6NIboLSc see here the steps followed in the video. Though its a slightly different scenario, you will get the gist of it pretty quickly as to how we can make another environment for our work and about installing TensorFlow properly.
Tensorflow supports 64-bit Python version. Make sure you have installed 64-bit Python 3.5/3.6/3.8 version.
Install Tensorflow using following steps
#check current python version
python --version
#Create the virtual environment
conda create -n tf python=PYTHON_VERSION
#Activate the tf environment
conda activate tf
#Install Tensorflow
pip install tensorflow

Categories