use tensorflow on pyCharm - bash

I am new to Deep Learning and I have just installed tensorflow on my Mac,
however, there are some problems.
I am sure I installed successfully because I can run tensorflow on Terminal using python 3.5
import tensorflow as tf
node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0) # also tf.float32 implicitly
print(node1, node2)
there is an output on my bash
Tensor("Const:0", shape=(), dtype=float32) Tensor("Const_1:0", shape=(), dtype=float32)
However, when I run import tensorflow as tf on Python Console of PyCharm. A problem occurred:
>>> import tensorflow as tf
ImportError: No module named 'tensorflow'

I just went through this a few days ago after switching to PyCharm. You have to select the right Project Interpreter so it can find the Python installation that includes Tensorflow. In the menu go to PyCharm->Preferences and under the section Project: PyCharm on the left select Project Interpreter. In my case, I select 3.5.2 (~/anaconda/bin/python) because there's where my Tensorflow seems to reside. Whatever versions you select, scroll through the window at the bottom to make sure you see Tensorflow listed as a Package.
IMPORTANT: in my case it seems that once you OK this, it takes a while for PyCharm to digest? Because for a while the 'Run' button is greyed out and you can't run your program. Took me a while to figure what I'm doing wrong, but looks like you just need to give it sometime and it picks it up and the Run button goes back to green. Hope this works for you...
I am using the Community Edition, for what it's worth...

I'm using PyCharm 2018.1.4 Community Edition on Fedora 28, and have TensorFlow 1.9.0 installed (through "sudo pip3 install --upgrade tensorflow"). Here is my step to load TensorFlow
File > Settings > Project > Project Interpreter > Change to "/usr/bin/python3.6" in Project Interpreter, then the installed Package will be loaded and displayed.
Good luck.

Related

Pycharm doent recognize numpy package from previously created conda environment

im using Pycharm 2022.2.3.
I have Anaconda Navigator 2.3.2. Created in anaconda a new virtual environment based on python 2.7 called testpy2. Added the numpy package needed to execute a code. I did it from Ananconda Navigator GUI. The installation was succesful. I could see now numpy in my installed package list.
Open Pycharm project, select as interpreter the existing conda environment test2py.
The code is:
import random
import numpy as np
print "Hola"
The problem is it give the error: ImportError: DLL load failed when importing Numpy.
So I cant execute the program because of numpy.
When i go to see the packages something similar to:
then i got stuck in loading. Pycharm should recognize and load all the packages in the conda environemnt as shown in the image above, but in my case i got stuck in loading.
Im running on Windows 10 and i dont have any python installed at all
Any help would be apreciated.

Clean install of Scientific Python without reformatting the disk

1st, the Disclaimer: I looked at numerous questions here, there is question about uninstalling all pip–installed, uninstalling matplotlib, moving to 3.5 from 2.7, –– but I didn't find an answer to my specific problem. Sorry if I didn't look hard enough.
Basically, my problem is I have a mess of different packages installed by different means at different times. Manifestations of this are:
1) I can import numpy from python but not from Jupyter notebook:
------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-5a0bd626bb1d> in <module>()
----> 1 import numpy
ImportError: No module named numpy
2) I cannot import nltk:
...
File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling
likely many more.
I recently uninstalled jupyter and anaconda, installed anaconda again, - this didn't help.
I cannot uninstall numpy / scipy , although I can use them (?!?):
>:~%python -c 'from numpy.random import rand; print rand()'
0.946167984715
>:~%pip uninstall numpy
Cannot uninstall requirement numpy, not installed
I have two versions of Python:
2.7.11 under /usr/local/bin/ pointing to /usr/local/Cellar/python/2.7.11/bin/python
2.7.10 under /usr/bin/ pointing to
/System/Library/Frameworks/Python.framework/Versions
-- although the default is 2.7.10 (numpy works with it), and I think 2.7.11 was added by Anaconda (incorrectly, because it doesn't see numpy).
Yesterday I uninstalled everything I could think of, then upgraded to a new version of Mac OS (10.12.2 Sierra), and then re-installed anaconda – in vain.
I am close to reformatting the disk and starting from scratch.
Is there a better option?
Thank you! and sorry for so many details.
Not sure exactly on a MAC but these are the things to try on windows and it is probably similar on MAC.
Start with a clean install of anaconda then try "where python" and "where jupyter" (it is "which" instead of "where" on linux). This tells you where it is looking for the executables. Both should be subfolders of anaconda. If they are not check your PATH variable.
Now start python or jupyter; import sys and try sys.path. That tells you where python is looking for stuff. It should look only in anaconda sub folders.

Installing pygame on Windows (custom Python location not supported?)

I am running Python 3.5 on Windows 8. I am trying to install pygame. I downloaded and ran
pygame-1.9.2a0.win32-py3.2.msi (6.4 Mb)
from
http://www.pygame.org/download.shtml
From python I get, after starting a new session:
>>> import pygame
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import pygame
ImportError: No module named 'pygame'
How do I install? Was my PythonPath updated? Looking at sys.path, it doesn't look like it. How do I get Python to see the library? Where was the library installed? Thanks for the help.
Update1:
The first step i the pygame intsaller states "Select Python Installations - Select the locations where pygame-1.9.2a0 should be installed." Underneath that is a selection that states "Python from another location". This doesn't make sense to me. Anyone?
Update2: I solved the problem - I reinstalled python in the default location (it wasn't before). The pygame installer doesn't seem to support custom installations. Ok, fixed. Thanks all for the help.
Up to now, Windows binaries must match the Python binaries. ...py-3.2.msi is for 3.2 and will not work with 3.5. Either get a 3.5 binary from the site you already used or use pip to install pygame-1.9.2a0-cp35-none-win32.whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/ Use pip install /? to get info on how to install from somewhere other than pypi. It might be easier to download the file to your machine first. The site above says a bit about this.
Make sure you have 32-bit python and pygame.

Installing numpy on mac with pip: "requirements already satisfied" but "No module numpy"

I have python2.7.8 on mac, things I did:
sudo easy_install pip - worked.
pip install numpy:
Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
I also did "pip upgrade numpy" - no luck. What's wrong?
Your problem is a conflict of different Python versions.
I would recommend installing Python and all the packages, such as numpy, scipy, matplotlib, pandas, etc via Brew
See this tutorial: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Homebrew-and-Python.md
You can verify which Python you're running with which python or which python3 in Terminal.
This solution is more flexible and cleaner in my opinion than using Conda/Miniconda. However it is also a bit more lengthy to install, as you need to have Xcode, devtools installed to build everything
Could it be that you have multiple versions of python installed? What happens if you run python using the full path like this:
$ /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2
instead of just python2?
In my experience on Mac (and other OS too) it is best to go with Anaconda / Miniconda. This is especially true for packages like NumPy and others from scientific stack.
While Anaconda is a full-blown distribution with about 200 packages, Miniconda is just Python with a few basic libraries. The big advantage is that all packages install as binary. Further, it makes it very simple and stable to install multiple Python versions side by side. For example:
conda create -n py27 python=2.7
creates a new environment with Python 2.7. Activate with:
source activate py27
Now:
conda install numpy
installs NumPy cleanly.
You can do the same for Python 3.5 and switch between environments with source activate.
After jumping from one stackoverflow answer to another I found the solution!
my problems were:
numpy at different location( actually at right, expected-to-be location). It was the IDLE that looks for its own default folder where python2.7 installed.
I checked that my numpy is working like this, run this script to check it is working:
import os
import sys
import pygame
sys.path.insert(0, '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python')
import numpy
pygame.init()
print "( using __version__): " + numpy.__version__
print numpy.version.version
user_paths = os.environ['PYTHONPATH']
print(user_paths)
sys.path insertion adds additional path to IDLE, so it knows where to look for numpy.
Then I check if numpy truly imported - i just print its version. Right now it is 1.8.0rc.
I want to find a way to avoid using this syspath insertion all the time.
So far so good - for now.
I had a similiar problem with numpy. However, it was resolved by choosing the right environment. If you are using VScode, open the command palette (ctrl+shift+p) and type
Python: Select Interpreter.
From there, try choosing the right virtual environment/Interpreter.

kmpfit module not in Kapteyn v2.2 module list

I am using Python 2.7 through Anaconda 2.7.8 and need Kapteyn 2.2 to perform Non-linear Least Squares fitting easily (it is probably an alternative to Scipy.optimize.leastsq() for dummies like me!).
After copy-pasting this from a previous post here on Stack Overflow:
conda install -c https://conda.binstar.org/dhirschfeld pyodbc
and then running on my cmd (as I did not have pyodbc installed I think, because of which maybe the command prompt on my Windows 7 64-bit system was not responding well to python setup.py install inside the Anaconda directory where I unzipped the Kapteyn .zip file downloaded from University of Groningen website.
But, after the installing pyodbc properly and running python setup.py install, the cmd gave me an error saying error: command 'C:\Users\windows 7\Anaconda\Scripts\gcc.bat' failed with exit status 1. Later, when I tried to import kmpfit module (needed for Non-linear least square fitting with Kapteyn), here is the problem:
import kapteyn
help(kapteyn)
Help on package kapteyn:
NAME
kapteyn - Kapteyn package.
FILE
c:\users\windows 7\anaconda\kapteyn\__init__.py
PACKAGE CONTENTS
_ni_support
celestial
doccer
filters
interpolation
maputils
mplutil
positions
rulers
shapes
tabarray
wcsgrat
DATA
__all__ = ['celestial', 'wcs', 'wcsgrat', 'tabarray', 'maputils', 'mpl...
__version__ = '2.2'
VERSION
2.2
As you can see, there is no module named kmpfit (or even wcs) here. But according to http://www.astro.rug.nl/software/kapteyn/intro.html, these two should be there.
Kindly help. I have never imported any module before.
Thanks in advance...:-)
I just managed to get this working (on Mac OSX, so you may have to adjust this). My steps were:
$ conda install pyodbc (didn't need to go through binstar)
Download & unarchive the kapteyn package, then navigate to its directory
$ python setup.py install, which used my OS's C compiler and Anaconda's python, and installed kapteyn to my anaconda distro's site-packages, as it should.
Check that kmpfit.so is in the kapteyn folder in site-packages, showing that kmpfit installed correctly.
>> from kapteyn import kmpfit failed, ImportError: cannot import name kmpfit. I did some digging and discovered that it was still importing kapteyn from the folder that I downloaded, not from site-packages.
Delete the downloaded kapteyn folder, then try again. It worked!

Resources