Python crashes when I import tensorflow - python

When I try to import tensorflow my python crashes. I tried uninstalling it and installing it again, but It isn't still working. Here is a picture of the command prompt when I try to import it.

I'm not too sure what the error is here.
try to pip list to see all packages
if no tensorflow seen then just pip install tensorflow
or print dir(tensorflow) to see functions
It seems you aren't executing anything but just importing the module.

Related

'No module named PIL' Visual Studio Code Error

I'm having a problem with PIL where vs code says there is no module named PIL when there is. If I run the file without vs code the module imports fine. In the vs code problem tab it says this:
import PIL could not be resolved from source. Pylance(reportmissingmodulesource)
I know the library is installed because if I do pip install pillow, it says requirement already satisfied.
Things I've tried to fix it: reinstalling python, uninstalling and reinstalling pillow, upgrading pip, installing the PIL library(pip install Pillow-PIL).
None of these things worked so I am out of ideas for things to try. Could someone help me with this?
This part is important:
If I run the file without vs code the module imports fine
If something like this happens, then you are not running the same python interpreter, because modules are always installed to specific installations of python that you have.
Do the following:
Add to your script the first two lines
import sys
print(sys.executable)
This will print the path to the python executable that is interpreting that script. If you now run this script with and without vs code, it should print two different python paths. Now you can install to the python interpreter that is being used by vs code specifically by typing
/path/to/python/used/by/vs/code/python -m pip install pillow
in case someone stil has this problem on Mac or it didn't work, I used the code "python3 -m pip install pillow" in my vs code in terminal below but I had different code "from PIL import ImageTk,Image"
If anyone stumbles upon this problem and can't figure out what's wrong:
the first thing to do is simply restarting the Visual Studio Code instance.
That worked for me after running pip3 install Pillow from the VSCode terminal.
How about this?
pip install Pillow
For reference: https://pypi.org/project/Pillow/

Runtime warning when importing libraries in jupyter notebook

So, I have never had this issue before on prior laptops- but recently on my new laptop- I get runtime warnings when trying to import libraries into Jupyter notebook- I'm not sure of the cause or how to fix it. Any solutions?
enter image description here
Maybe there is some problem with the package which showing warning. Try to re-install the package.
First check whether the package working properly. If not install the pakage. Here in your screenshot it shows problem with numpy. To install numpy follow
pip install numpy
Or
python -m pip install numpy
If the packages are working but still warning persist, then put the below code to remove the warning.
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')

I am installing the Detecto library in anaconda environment but it fails while importing

As a source, I apply the guide here:
Object Detection
I applied the pip3 install detecto command as shown here and it was successfully installed. But when I run python and try to run the detecto command, I get an error. How can I solve it?
Operation:
I don't think you can import detecto directly. Use from detecto import <lib> . Try from detecto.core import Model and see if it works in your terminal

Cannot Import Python Packages on Linux

I ran this in the terminal to install all the packages for a machine learning project.
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
It says the packages are already their newest version. When I run import numpy from the interpreter prompt, it just runs without a flaw.
But when I say numpy.version it says "module 'scipy.version' from '/usr/lib/python2.7/dist-packages/scipy/version.pyc'" without showing the version name. Also, the package import fails when I try a script.
On further experimentation, I figured a script as simple as
# Check python
print('Hello world')
is giving this error from a .py file,
./Script.py: line 2: syntax error near unexpected token `'Hello world''
./Script.py: line 2: `print('Hello world')'
Note that the script and version.version commands run fine from the terminal interpreter prompt.
Is something wrong very deep down?
Python version 2.7.12.
In order to get to know the version in python,
import numpy
print numpy.__version__
numpy.version gives the path.
If you want to check the version of numpy, try this:
import numpy
numpy.version.version
As for the following question, please post more information.

Why can't I import opencv3 even though the package is installed?

I currently am running Python 3.5 and using Spyder from Anaconda as my IDE. I am running this on a Windows machine.
When I write import cv3 at the top of my code, it returns the error ImportError: No module named 'cv3'
I attempted to install opencv3 again with the command conda install -c https://conda.binstar.org/menpo opencv3 in the Command Prompt. It is apparently already installed because it returned
Fetching package metabase...............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Users\Joey\Anaconda3:
# opencv3 3.1.0 py35_0 https://conda.binstar.org/menpo
Am I importing cv3 wrong? How do I fix this error?
Update: Tried import cv3 instead of import cv2 but got the following error: ImportError: cannot import name 'cv2'. The wording on the two errors is different, so python must acknowledge there is opencv installed but it does not work for some reason. Any ideas?
Ironically enough, the module is still called cv2 because it doesn't represent the version of opencv but the actual C++ API underneath which is, to be contrasted from the C API, named - cv2... So try with: import cv2
Problem solved by using command pip uninstall opencv-python in the Command Prompt.
I have attempted several installations of opencv and I suppose one may have downloaded badly and Anaconda was attempting to read that one. I looked into the build of some of the other installations I attempted and some were for Python 2.7. Maybe that contributed to the error.
Thankfully, this worked. Now import cv2 works perfectly. No errors.
I used the same approach to install the package. However, I could not import the library using the name opencv3. I had to use cv2 which worked for me.
Elaborating on #zwer's answer, check the version of OpenCV after import cv2.
>>> cv2.__version__
'3.1.0'
So basically it's calling the OpenCV3 library.

Categories