Installing matplotlib on windows 10 python 3.6 - python

HI I am following an install from a book "Python Crash Course" chapter 15 which directed me to install matplotlib via downloading from pypi and using the format
python -m pip install --user matplotlib-2.2.2-cp36-cp36m-win32.whl
This seems to go ok but reports at the end.
File "C:\Program Files (x86)\Python Community\Python 3.6.1\lib\decimal.py", line 3 in , from decimal import *
AttributeError: module 'numbers' has no attribute 'Number'
and when I enter an interactive shell:
import matplotlib
I get a ModuleNotFoundError
I have tried a matplotlib-2.2.2-cp36-cp36m-win32.whl and matplotlib-2.2.2-cp36-cp36m-win_amd64.whl both give the same error.
Could someone please let me know how to fix this?

I am answering my own question.
The issue was to do with a file called numbers.py residing in a folder that I have all my python files, wheel files etc.
I found the answer in stack overflow. I will link to this matplotlib - AttributeError: module 'numbers' has no attribute 'Integral'.
The file was stopping the install so I renamed it and reinstalled matplotlib and it now works.
Sorry but this was not obvious to me !

Try running cmd as administrator inside the python directory. Then execute:
pip3 install matplotlib-2.2.2-cp36-cp36m-win32.whl
Also make sure that you have all dependencies installed.

The code seems very specific and something may not be supported any more.
You could first uninstall the current version using:
pip uninstall matplotlib
and then try installing matplotlib as follows:
pip install matplotlib
providing that you have admin rights to do so.
Then you can import as: import matplotlib.pyplot as plt

It seems like you are installing the package on Python 2.
Try installing the library using:
py -3 -m pip install --user matplotlib
Assuming you are using Windows.

Try doing as below:
python -m pip install --user matplotlib

Related

Module installed but not found when import

I've got a documentation of the package named 'Google-Images-Search'
https://pypi.org/project/Google-Images-Search/
I've read and tyr to reproduce what's needed, so I installed it with this commandline :
pip install Google-Images-Search
Now when I'm trying to do it again, I've got the message like "Requirement already satisfying" for all dependencies and nothing append after.
So I've develop the file index.py with this inside
from google_images_search import GoogleImagesSearch
gis = GoogleImagesSearch('test1', 'test2')
But when I execute this, I've got
No module named Google_Images_Search
I already try to put in my code
help("modules")
But Google_Images_Search is not here at all
That more than 2 hours I'm on it, I've try to uninstall pip, pip3, use pip or pip3, reinstall, use python -m pip install ... But nothing work...
Please I don't understand, and I'm beginner with Python and a little with Raspberry and the Linux environment.
The documentation states that the name of the module that the project installs is google_images_search, all lowercase, not Google_Images_Search.
try changing your import,
from google_images_search import GoogleImagesSearch

ImportError: No module named IPython

When i try to use from IPython.display import clear_output, display_html, then i show the error:
(ImportError: No module named IPython)
I am using Python 2.7.13, and im trying to make the game of life from John Conway. I am following this link: http://nbviewer.jupyter.org/url/norvig.com/ipython/Life.ipynb
I have read another questions and answers about it, but any answer works for me. First, this error is showed in command line, and when i try to run this code in a file. Second, this error is direct to IPython, not submodule or something similiar.
Ok, finally i achieved my goal.
I wrote ipython --version but i found, it was not installed.
I tried to install it, with pip. I went to C:\Python27\Scripts, here is pip, you can try in this directory, or add to environment variables.
I tried to install ipython, but i found a error
error: Unable to find vcvarsall.bat
so i installed visual studio c++ 9.0, the version to python 2.7.
pip install ipython
If you scrolled this far you may want to try:
import IPython
as opposed to import Ipython. Notice that 2 letters are capitalized
For Anaconda try,
conda install -c anaconda ipython
Use this code to install the IPython library:
!pip install ipython
import IPython
Well, this works on Google Colab.
This is most likely because ipython is not installed.
You can install it with pip.
pip install ipython
If you are using Anaconda (the full version) ipython comes preinstalled. If you are using Miniconda or if the ipython is deleted for some reason you can re-install with
conda install -c anaconda ipython
If you are using it with jupyter. You might want to register the ipython with a user.
python -m ipykernel install [--user] [--name <machine-readable-name>] [--display-name <"User Friendly Name">]
Reference :
Official Documentation
I have a similar issue, but it appears when I was running the script under sudo. Fast and easiest way was to install IPython under sudo.
sudo pip3 install IPython
I am running a script that uses IPython module, in my terminal. If you are also trying to do something similar, this answer might help you.
!pip3 install IPython
Things to keep in mind:-
'I' and 'P' in IPython are uppercase.
I am running the above command in python 3.7.
you need to import
from IPython.display import Image
initially, I imported
from IPython.display import image
so there is Image not image
For me, the problem (that drove me crazy) is that I actually needed capitalization. The correct import after pip install is:
from IPython.display import display, update_display
etc.

ImportError: No module named 'pandas'

I am trying to learn pandas and I haven't been able to import it into my code.
I have looked at other answers on this site and none of them have worked.
I just installed anaconda and installed everything through conda.
Here is a sample script that I am trying to run.
import pandas as pd
writer = pd.ExcelWriter('farm_data.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')
workbook = writer.book
worksheet = writer.sheets['Sheet1']
chart = workbook.add_chart({'type': 'column'})
And the error it kicks back.
Traceback (most recent call last):
File "C:\Users\thiet01\Documents\Python Scripts\new 1.py", line 1, in
import pandas
ImportError: No module named 'pandas'
If you need any more information, please let me know and I can provide it.
Thanks in advance for any help.
below solved my issue:
apt-get install python3-pandas
or
apt-get install python2-pandas
Font: https://ask.fedoraproject.org/en/question/36529/installing-python-pandas/
I had the same problem for a long time. Today I tried a whole day and it finally worked. Below is the steps how I did it. I don't have theory for why the problem exist and how it is solved. I just know the following steps helped me get pandas going.
A. download first and install miniconda using the following code:
bash Miniconda2-latest-MacOSX-x86_64.sh
B. create an env for your project using following code:
conda create --name trypandas numpy pandas jupyter
C. going to your env and try jupyter notebook with pandas using:
source activate trypandas
jupyter notebook
Note: my own experience indicates:
when I missed conda install jupyter, pandas only work in pure python environment, not in ipython nor in jupyter notebook;
after conda install jupyter, pandas works in jupyter notebook now.
the step B above installing jupyter together with numpy and pandas, there should not be a problem.
My trypandas in installed in ~/miniconda2/envs.
Here is the basic documentation on how to instal python packages.
For OS X and Linux users, the following command ought to work:
pip install pandas
Even I had same issue but this solved my problem-
sudo apt-get install python-pandas
To check if pandas is installed or not:
Open up a Python prompt by running the following:
python
At the prompt, type the following:
import pandas
print pandas.\__version__
This will print the installed version of pandas in the system
I wanted to add this as a comment but Im not special enough yet in the eyes of stackoverflow.
Some modules need to be separately installed into your libraries folder of your python directory.Using pip (https://pip.pypa.io/en/stable/) is helpful for this. Otherwise manually add the module to your library folder by installing the module at:
https://pypi.python.org/pypi/pandas/0.18.1/
running the setup through the command line ((pandas location)>setup.py install), and finally adding it to your python directory.
Hope this helps!
What worked for me was to make sure that I run the command sudo apt-get so you run as root to make sure I download python3 like below
sudo apt-get install python3
The reason you need to use sudo it's because environments such as Ubuntu lock the root automatically according to Wikihow
Then I used
sudo apt-get update
sudo apt-get upgrade
And then I used the pip install pandas
That worked for me. I hope that's helpful
For installing pandas you can also use following method in python3.
python3 -m pip install pandas
or
pip3 install pandas
Also if this still fails because of a build error
ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly
or takes a long time to install pandas, then try upgrading pip.
pip3 install --upgrade pip

Unable to import tweepy module

I am new to installing new python modules.
I installed tweepy using pip install tweepy. The installation was successful and 2 folders tweepy & tweepy-3.3.0.dist-info are created in the Lib/site-packages, hence I assumed all should be fine.
However, when I went to the IDE and import tweepy. It is unable to detect the module:
>>> import tweepy
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named tweepy
What is wrong?
I am running python 2.7.5.
[Update 1] I am using windows 7.
I first installed pip using another forum's suggestion (How do I install pip on Windows?). basically saving the get-pip.py script and double clicking it (unable to get "python get-pip.py" to work in cmd prompt as suggested). Then, I went to cmd and nagivated to C:/Python27/Scripts and type in pip install tweepy. I remembered seeing the result as a successful installation.
[Update 2] Using a file with import tweepy and running it, I have a similar error.
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\xxxx\Desktop\Script1.py", line 2, in <module>
from tweepy import Stream
ImportError: No module named tweepy
[Update 3] Typed "pip freeze" in cmd. It does show tweepy=3.3.0
C:\Python27\Scripts>pip freeze
oauthlib==0.7.2
requests==2.7.0
requests-oauthlib==0.5.0
six==1.9.0
tweepy==3.3.0
wheel==0.24.0
[Answer] Thanks for all the help guys, especially Cleb & omri_saadon suggestion that there might be something wrong with the file path.
I just realised that my GIS software, ArcGIS by default installed another Python into the Python27 folder, and everything is taken from that folder, C:\Python27\ArcGIS10.2, instead of C:\Python27. After I install tweepy from C:\Python27\ArcGIS10.2\Scripts, everything works well.
Try to pip uninstall tweepy
and then again pip install tweepy
Make sure you don't have several interpreters on your computer, if you have several, make sure that your pycharm(or any other editor you use) is configured with the same interpreter where you installed tweepy.
I tried this command py -m pip install tweepy and worked for me
If you are using Anaconda
conda install -c conda-forge tweepy
you may also use
easy_install tweepy
If you are using ubuntu try: sudo apt install python-pip
and then run: python3 -m pip install tweepy
I hope that helps!
If you are using conda enviroments and jupyter notebooks, you could try to install it from the notebook and restart the kernel:
!conda install -c conda-forge tweepy
The problem is that , tweepy in getting installed in the native python environment, i.e you might be able to import it in cmdline but must be getting error in jupyter notebook.
If this is the case, then you might need to install it with conda environment , with conda install tweepy. But if in this case also if you fail to install it due to conflicts errors thrown by conda do the following.....
Copy all the required tweepy pip files from the python environment, which you can find by running the pip install tweepy cmd which shows that the required package is already satisfied in a particular path.
You might be required to copy tweepy, requests, requests_oauthlib, oauthlib.
Paste the copied files into site-packages inside of Anaconda environment folder.
This solved the problem for me , hope it solves for you too.
If multiple versions of python are installed on the computer, you need to make sure under which version the package has been installed into. I have two versions of python installed on my mac, both python2 and python3 under /usr/local/lib path.
pipinstall tweepy only installs the package into python2.7/site-packages, while VSCode complies python3. Run pip3install tweepy to get the package under python3.7/site-packages so the module can be recognized by the compiler.
I had the same issue where after installing/ uninstalling via pip it still did not work. As a last ditch effort I actually moved the 'tweepy' folder in the '...Lib > site-packages' back to the main Python directory and 'import tweepy' then worked. No idea why this worked, but it did for me... Good luck!
I tried this, I was having the same error, but the thing that I did was, first installing the package using pip command, then spot the path where it got stored, then using os module change the directory to where the packages got stored, and then import it, it will work..
Very common error wherever your computer have different python environments in pycharm. Your computer may have different python interpreters as you install pip several times. Try to config the exact python interpreter using the following steps. PyCharm, Settings -> Project Interpreter -> This will show the installed package list and dedicated interpreter at the top right-hand side. Try your right interpreter within the dropdown.
If you are using Jupyter Notebook, just run the command below in the cell of the notebook.
!pip install tweepy
If you are using Jupyter notebook on Anaconda try:
sudo conda install tweepy
This worked for me on OSX.
The same for me, typing direct in the console import tweepy it works, but when I tried to run from the script it says 'No module named 'tweepy'' i tried to uninstall and install again but the solution was more simple,
instead of run like
C:\script.py
I run
C:\python script.py
It works, Python version is 3.6.2 tweepy version is 3.5.0
If you are using Jupyter Notebook, the only thing that worked for me was to first install Jupyter again
pip install jupyter
and then install tweepy
pip install tweepy

ImportError: no module named win32api

I am using Python 2.7 and I want to use pywin32-214 on Windows 7. I installed pywin32-214 by using the MSI installer. But when I import win32api in my Python script, it throws the error:
no module named win32api
What should I do? How can I use win32api on Windows 7?
This is resolve my case as found on
Where to find the win32api module for Python?
pip install pypiwin32
According to pywin32 github you must run
pip install pywin32
and after that, you must run
python Scripts/pywin32_postinstall.py -install
I know I'm reviving an old thread, but I just had this problem and this was the only way to solve it.
I had an identical problem, which I solved by restarting my Python editor and shell. I had installed pywin32 but the new modules were not picked up until the restarts.
If you've already done that, do a search in your Python installation for win32api and you should find win32api.pyd under ${PYTHON_HOME}\Lib\site-packages\win32.
I didn't find the package of the most voted answer in my Python 3 dist.
I had the same problem and solved it installing the module pywin32:
In a normal python:
pip install pywin32
In anaconda:
conda install pywin32
My python installation (Intel® Distribution for Python) had some kind of dependency problem and was giving this error. After installing this module it stopped appearing.
I had both pywin32 and pipywin32 installed like suggested in previous answer, but I still did not have a folder ${PYTHON_HOME}\Lib\site-packages\win32.
This always lead to errors when trying import win32api.
The simple solution was to uninstall both packages and reinstall pywin32:
pip uninstall pipywin32
pip uninstall pywin32
pip install pywin32
Then restart Python (and Jupyter).
Now, the win32 folder is there and the import works fine. Problem solved.
After installing pywin32
Steps to correctly install your module (pywin32)
First search where is your python pip is present
1a. For Example in my case location of pip -
C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts
Then open your command prompt and change directory to your pip folder location.
cd C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts
C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts>pip install
pypiwin32
Restart your IDE
All done now you can use the module .
The following should work:
pip install pywin32
But it didn't for me. I fixed this by downloading and installing the exe from here:
https://github.com/mhammond/pywin32/releases
This line:
import win32com
got me the error no module named win32api.
Using this command in elevated terminal:
pip install pywin32-ctypes and
pip install pywin32
and based on the error displayed, replacing:
import win32api → from win32ctypes.pywin32 import win32api
import pywintypes → from win32.lib import pywintypes
import _win32sysloader → from win32 import _win32sysloader
in your source file, or even the files of the packages that report the error (know what you are doing if you choose this approach) may solve this error. But better would be to just add the corresponding directories into the python path variable, for better integration with the python loading system, more info here: https://realpython.com/python-import/
So I put this content:
python38.zip
.
./lib
./lib/site-packages
./lib/site-packages/win32
./lib/site-packages/win32/lib
./lib/site-packages/win32ctypes/pywin32
./lib/site-packages/win32ctypes
# Uncomment to run site.main() automatically
#import site
(order DOES matter)
into this file: <python_root_installation_directory>/python38._pth
That way, correct libraries load when standard imports are used. If there is a cache import somewhere in the library, it will work, and the imports inside the libraries work as well.
This works for me and my installation, so your environment may be set up differently and this guide may not be fully compatible, but it is a good step in solving the issue, maybe modification or extension of my steps above may lead to the solution in another distribution.
Try this, it worked for me, it may help you!
pip install pywin32==225
I've tried all of your answers and finally got a solution. my issue was that I installed from both pip and python interpreter on my Pycharm IDE. I just removed win32compact from my interpreter and it works.
let me summarize, correct me if wrong, as below:
# update to newest pywin32
python -m pip install -U pywin32 pypiwin32
# run the post-install #ref https://stackoverflow.com/questions/21343774/importerror-no-module-named-win32api
python %CONDA_PREFIX%\Scripts\pywin32_postinstall.py -install
# double check
python -c "print( __import__('win32api') )"
In my case, the only thing that worked was to download the appropriate wheel from: https://pypi.org/project/pywin32/#files, and install with --force-reinstall.
pip install pywin32-300-cp37-cp37m-win_amd64.whl --force-reinstall
I found solution here:
https://www.ti-enxame.com/pt/python/pywin32-e-python-3.8.0/813327700/
I was able to run it on Spyder without error, but It wasn't working on cmd prompt
I just import the module pywintypes before win32api
import pywintypes
import win32api
I tried to reinstall pywin32, installed different versions, but nothing could make pywin work. The only thing that did finally help me was running
python pywin32_postinstall.py
which is located at Anaconda3\Scripts folder. Thanks for sameer_nubia for highlighting the location.
I solve this by
python -m pip install -U pywin32 pypiwin32

Categories

Resources