No module named 'plotly' - python

I am new to python and I'm following a tutorial using python3. I installed plotly and I can see it in the pip list and pip3 list and python help("modules"). However, when I tried to import the module (from plotly import offline) I got the error:
ModuleNotFoundError: No module named 'plotly'.
Tried to reinstall but it did not work.
I can import other modules in the list, like pygame or matplotlib without a problem.

It is usually a good idea to create a virtual environment to install additional modules. This will create a sealed Python environment with only the packages you specify. This usually fixes such errors, as Python sometimes installs packages where they can later not be found anymore. It is also a good idea to not use pip, as it might point to a pip from a different python version. Also it makes sense to upgrade pip before installing packages.
Try the following:
python3 -m venv env
. env/bin/activate (on Linux)
.\env\Scripts\activate (on Windows)
Check which packages we have:
python -m freeze
Here make sure this does not show anything except pkg-resources==0.0.0. Otherwise your PYTHONPATH might be mesed up.
Upgrade pip and install your package:
python -m pip install --upgrade pip
python -m pip install plotly
Run python and import your package:
python
>>> import plotly

If I typ this:
pip install plotly
in a CMD and this:
>>> from plotly import offline
In the interpreter it workes fine,
try uninstalling and reinstalling plotly:
pip uninstall plotly
Enter
y when it says Proceed (y/n)?
And install again with
pip install plotly

I had the same problem; after uninstalling/installing plotly, use venv, I realised (after 2h) that my script name was "plotly.py" => that was the cause of the error

Related

No module named 'PIL' after Installing pillow latest version

I am installed pillow,following the documentation here,
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
and import Image like this:
from PIL import Image
Even though I upgraded Pillow to 9.4.0, I am getting the following error in vscode
No module named 'PIL'
I am using Python 3.9.7. I am not sure what I am doing wrong here, is it my python version or is it the vscode. Can someone please enlighten me about this issue.
I can see them installed in my venv folder, but cannot access it in the file I am working on (which is highlighted by yellow)
Add this code to your script.
import sys
print(sys.path)
Ensure that your sys.path contains the path "$PROJECT/venv/lib/python3.9/site-packages"
If it doesn't, your virtual environment is broken. Try this instead:
Use this command to remove the current environment. rm -rf venv
Create it again. python -m venv venv
Install all your dependencies and run pip install --no-cache-dir Pillow
Make sure your environment is functioning properly right now.
I currently have also problems with vscode venv because they dont get which packages are installed ...
if you have installed the package in the venv and selected the venc (source .venv/bin/active) there should be no problem running it. It only seems to be a linter problem.
By using my system python installation interpreter and have installed the packages there I dont get the error

PyAutoGUI won't import even with installed package

After utilizing pip to install pyautogui successfully to my Python3.10 environment I'm utilizing in Visual Studio, I'm still getting this error when trying to simply import the library.
Warning (active) reportMissingImports Import "pyautogui" could not be resolved
I know it's installed to my correct repo, as I can see PyAutoGui (0.9.53) listed under packages of my active environment from the Solution Explorer. I also have th
I've tried a good few attempts to reinstall using pip and pip3 in separate attempts, but get "Requirement already satisfied" in return.
I'm new to Python and programming in general so any tips or assistance would be appreciated.
I've had similar issues like this before.
What python does is it looks in it's site-packages folder for the package, If you have multiple python versions installed sometimes the packages will be installed for one python version instead of the one you want.
This is what you can do.
Run
pip show pyautogui
This should output something like this:
/Users/<user>/.local/share/virtualenvs/place/lib/python3.8/site-packages
This is where your pyautogui module is installed at.
Now using python run this code.
import sys
print(sys.path)
Now the sys.path should contain the same site-packages path shown when we ran 'pip show pyautogui'
If sys.path does not contain the pyautogui site-packages path then that means pip installed pyautogui for the wrong python version.
I believe running pip with this command should install pyautogui to the correct python version.
python<version> -m pip install pyautogui
Example:
python3.8 -m pip install pyautogui
You can find out your python version by running:
python --version

ImportError: No module named matplotlib.pyplot Python [duplicate]

I am currently practicing matplotlib. This is the first example I practice.
#!/usr/bin/python
import matplotlib.pyplot as plt
radius = [1.0, 2.0, 3.0, 4.0]
area = [3.14159, 12.56636, 28.27431, 50.26544]
plt.plot(radius, area)
plt.show()
When I run this script with python ./plot_test.py, it shows plot correctly. However, I run it by itself, ./plot_test.py, it throws the followings:
Traceback (most recent call last):
File "./plot_test.py", line 3, in <module>
import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot
Does python look for matplotlib in different locations?
The environment is:
Mac OS X 10.8.4 64bit
built-in python 2.7
numpy, scipy, matplotlib is installed with:
sudo port install py27-numpy py27-scipy py27-matplotlib \
py27-ipython +notebook py27-pandas py27-sympy py27-nose
pip will make your life easy!
Step 1: Install pip - Check if you have pip already simply by writing pip in the python console. If you don't have pip, get a python script called get-pip.py , via here: https://pip.pypa.io/en/latest/installing.html or directly here: https://bootstrap.pypa.io/get-pip.py (You may have to use Save As ..)
Step 2: Take note of where the file got saved and cd the directory from command prompt. Run the get-pip.py script to install pip.
You can write in cmd this line within quotes: "python .\get-pip.py"
Step 3: Now in cmd type: pip install matplotlib
And you should be through.
You have two pythons installed on your machine, one is the standard python that comes with Mac OSX and the second is the one you installed with ports (this is the one that has matplotlib installed in its library, the one that comes with macosx does not).
/usr/bin/python
Is the standard mac python and since it doesn't have matplotlib you should always start your script with the one installed with ports.
If python your_script.py works then change the #! to:
#!/usr/bin/env python
Or put the full path to the python interpreter that has the matplotlib installed in its library.
If you are using Python 2, just run
sudo apt-get install python-matplotlib
The best way to get matplotlib is :
pip install matplotlib
cause the previous way may give you a old version of matplotlib
This worked for me, inspired by Sheetal Kaul
pip uninstall matplotlib
python3 -m pip install matplotlib
I knew it installed in the wrong place when this worked:
python2.7
import matplotlib
use pip3 install matplotlib to install matlplot lib.
By default, pip will install those package for 2.7 as it the native one.
using pip3 makes it specific for python 3, and make sure you have only one version of python 3
First check the version of Python
For python2:
sudo apt-get install python-matplotlib
For python3:
sudo apt-get install python3-matplotlib
If you mismatch the Matplotlib installation and the Python version you will get the no-module-error because no module for that version exits.
If you using Anaconda3
Just put
conda install -c conda-forge matplotlib
You can install the matplotlib package in python 3 by doing this
python3 -m pip install matplotlib --user
It's working for me.
If you have pip installed and Python configured to the path variables, Just run this command in the terminal.
pip install matplotlib
So I used python3 -m pip install matplotlib then import matplotlib.pyplot as plt and it worked.
I had a similar problem, using pip3 and all these things worked for installing matplotlib but not pyplot. This solved it for me:
import matplotlib as plt
from matplotlib import pyplot as pllt
I had a similar issue that I resolved and here is my issue:
I set everything up on python3 but I was using python to call my file for example:
I was typing "python mnist.py" ...since I have everything on python3 it was thinking I was trying to use python 2.7
The correction:
"python3 mnist.py" - the 3 made all the difference
I'm by no means an expert in python or pip, but there is definitely a difference between pip and pip3 (pip is tied to python 2.7) (pip3 is tied to python 3.6)
so when installing for 2.7 do: pip install
when installing for 3.6 do: pip3 install
and when running your code for 2.7 do: python
when running your code for 3.6 do: python3
I hope this helps someone!
I bashed my head on this for hours until I thought about checking my .bash_profile. I didn't have a path listed for python3 so I added the following code:
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
And then re-installed matplotlib with sudo pip3 install matplotlib. All is working beautifully now.
The file permissions on my virtual environment directory and my project directory were not correct and, thus, would not allow me to install the proper packages. I upadated them by running:
sudo chown user:user -R [project folder]
sudo chown user:user -R [environment folder]
In the above your should use your own usernames in place of "user". The -R recurses through all subfolders and files.
Working on the django project and faced same problem,
This is what I did.
Check if you have matplotlib already simply by writing pip show matplotlib in the python terminal.
If dont, run the command pip install matplotlib.(make sure you have pip downloaded)
Run the command pip show matplotlib again.
If the library is successfully downloaded, you can run your project (py manage.py runserver)
If you are in a venv, don't install these libs within the venv.
Installing them from outside helped me.
For me, with PyCharm and Python 3.8 on WIN10 environment, the solution was inside the IDE of PyCharm itself.
From the IDE and Project Setting (the gear on the top right corner), I've chosen Settings -->Project:Python-->Python Interpreter and you can see all the packages installed (and matplotlib wasn't present in the Package list).
Click on the + icon in the upper left corner for Package installation, and next will be opening a new window with the available packages for PyCharm. In the find box was sufficient to type matplotlib, select it and click on Install Package.
Here a screen-shot of PyCharm environment (as requested on 21/08/2021) :
If you experienced this error ModuleNotFoundError: No module named 'matplotlib' while using venv and running pytest like me, you can check by comparing the path type pytest shows and the path type python shows. In my case pytest wasn't under venv/bin directory like python, I installed pytest by pip and reactivated venv. See https://stackoverflow.com/a/54597424/3622415
I have installed matplotlib using both pip and conda but experienced this error ModuleNotFoundError: No module named 'matplotlib' .
I fix by following.
Because It might have an old version of Jupyter notebook, so i try this command to install it in the current kernel.
import sys
!{sys.executable} -m pip install seaborn
In the New Jupyter version (2019) can be installed simply as:
%pip install matplotlib
I solved by conda. Once installed miniconda or anaconda, type
conda install matplotlib
then, when prompted, type
y
in sublime text you can set
"cmd": ["python3", "-u", "$file"]
in tools > buildsystem > new build system
it worked for me

No module name 'tensorflow'

The requirements for the code to run is
Python 2.7
TensorFlow 1.n
SciPy & NumPy
I have python 2.7.8 by checking python --version. Installing them on python website also lead to a message saying there is no software to install so I assumed that I already have python 2.7x
For tensorflow I have install it using pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0-py3-none-any.whl
and for Scipy and numpy i did brew install numpy scipy ipython jupyter
I have a python env setup call mypython.
Using pip list I have the following modules install as shown in the image.
But still VScode prompt an error and say that No module named 'tensorflow'when i run the code file.
How do I solve this?
enter image description here
Install Python extension instead of MagicPython;
You're using mypython in integrated Terminal but in left bottom corner, you select the global one,which is python3.10.1 as interpreter. Open Command Palette and choose Python: Select Interpreter, select mypython then reload window,the error should go away
Think you might be using the wrong pip. Could you run following in your terminal, with your venv activated.
$ pip --version
$ pip3 --version
Try installing with pip instead of pip3

Problems with installing matplotlib in python 3.6

I'm trying to teach myself python, and I feel out of my depth. To start, I am working on a mac which already comes with python 2.7 installed.
I installed python 3.6 recently and have been using it to teach myself the basics. I'd like to eventually learn how to produce mathematical plots in python, and I know I will need the matplotlib package to do that.
Following some advice online, I was told that python3 already comes with pip installed, which is what I thought I should use to install matplotlib. The advice said I should type the following into the mac terminal:
python3.6 -m pip install matplotlib
I typed this, and it seemed like the package was installing, but I ended up getting some sort of error code that said:
Command "python setup.py egg_info" failed with error code 1 in [folder].
I tried opening IDLE and typing "import matplotlib", but I got the error: "no module named matplotlib". I also tried typing "import matplotlib.pyplot as plt", but I got the same error.
Based on further research and this youtube video, I've decided to just install miniconda in order to have access to the matplotlib package.
The problem is, I'm not sure if I should somehow be uninstalling whatever was installed when I ran the code above to install matplotlib. I've actually run that line of code 3 or 4 times. Should I remove anything before installing miniconda? Also, I am running python 3.6, while miniconda is listed on the website as being for python 3.5. Does this mean it won't work for my version of python?
Running pip like that would install packages system-wide. I'm guessing it's failing because you're not running as root (i.e. the administrator user). But wait! Don't try again as root! Instead of installing packages, do it in a virtual environment. First create it:
virtualenv myenv
This creates a directory called myenv with a bunch of stuff in it (so make note of where you run this command). Whenever you want to use the virtual environment (like straight away!) you first need to activate it:
. myenv/bin/activate
Don't miss out that dot (followed by a space) at the beginning! As the other answer says, the first thing you should do in it is upgrade pip:
pip install --upgrade pip
Now you're ready install whatever else you like:
pip install matplotlib
One last note: The virtual environment is tied to a particular Python version. By default it uses the system's Python 2.7 installation, so to use a different one you need to specify it when you create the virtual environment, like this (if that Python version is installed system-wide):
virtualenv -p python3.5 myenv
Or like this (if that Python version is not installed system-wide):
virtualenv -p /path/to/my/installation/of/python3.5 myenv
While the virtual environment is activated, you don't need to specify the particular path/version of Python. Just run it like this:
python
I also encountered many problems during my installation.
It seems that version 2 of matplotlib is not compatible with Python version 3.
Finally, I succeeded by specifying version 3 of matplotlib as follows with the following command:
sudo apt-get install python3-matplotlib
Reference from the Matplotlib website:
https://matplotlib.org/users/installing.html#building-on-linux
Try upgrade setup tools
--upgrade setuptools
or
easy_install -U setuptools
or upgrade pip
pip install --upgrade pip
I ended up downloading anaconda and using the python interpreter that comes with it, as anaconda comes with matplotlib and many other python packages of interest.
the pip command typically is for the Python 2. use pip3 instead to install the libraries in the python 3.X path
This should work
pip3 install matplotlib
The solution that work for me in python 3.6 is the following
py -m pip install matplotlib
Matplotlib files are downloaded in ~/.local/lib/python3.6/site-packages/ and not in /usr/lib/python3.6/ .
Try the command:
sudo cp -r ~/.local/lib/python3.6/site-packages/* /usr/lib/python3.6/

Categories