How to Install Matplotlib Basemap Module on Windows 7 with WinPython (or any Python stack install)? - python-2.7

I've found that the Basemap (module for matplotlib and Python) binary installer for Windows cannot detect Python on the system when Python is installed as part of a stack install, like Anaconda or WinPython. The installer exits, rather than allow you to point to the directory of installation.
I have to therefore install via source. However, I don't know the method to do this. The Readme.txt and install instructions don't seem to help. They simply instruct to "install geos-3.3.3 first" - well, how exactly? I don't see a setup.py in that directory.
Any help would be great. (Python 2.7, Win 7, 64b)

I use windows. And my installation failed with official guidance, too.
Finally I installed Basemap using the following method. Although I am not sure if it will go right for you, I just offer mine.
First of all, you must have pip in your computer. (It is much easier
to install, compared with Basemap and other things. And it can be
used to install many useful packages.)
Then go this great link: http://www.lfd.uci.edu/~gohlke/pythonlibs/
And download the file named "basemap‑1.1.0‑cp27‑cp27m‑win32.whl".
Move the .whl file to directory "C:\Python27". (Maybe you
installed your python in different disk, then change it
accordingly.)
Open terminal. (Use cmd or Git Bash or something else.)
Use command:
pip install basemap‑1.1.0‑cp27‑cp27m‑win32.whl

The following worked for me using Python 3.10.1.
Setup environment using terminal in Visual Studio Code (https://code.visualstudio.com/docs/python/python-tutorial):
py -3 -m venv .venv
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
.venv\scripts\activate
Install basemap using pip:
pip install matplotlib
pip install basemap-data
pip install basemap-data-hires
pip install basemap
Create file with code from: https://matplotlib.org/basemap/users/examples.html
Remember to select the correct interpreter (In VSCode use Ctrl+Shift+P to select interpreter).
That's it.

Related

Unable to find pygame.image.load [duplicate]

I have installed python 3.3.2 and pygame 1.9.2a0. Whenever I try to import pygame by typing:
import pygame
I get following error message :
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import pygame
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygame
ImportError: No module named 'pygame'
>>>
I went through some of the questions related to this error but none of the solution helped.
I have 64 bit machine with Win7 OS
go to python/scripts folder, open a command window to this path, type the
following:
C:\python34\scripts> python -m pip install pygame
To test it, open python IDE and type
import pygame
print (pygame.ver)
It worked for me...
Here are instructions for users with the newer Python 3.5 (Google brought me here, I suspect other 3.5 users might end up here as well):
I just successfully installed Pygame 1.9.2a0-cp35 on Windows and it runs with Python 3.5.1.
Install Python, and remember the install location
Go here and download pygame-1.9.2a0-cp35-none-win32.whl
Move the downloaded .whl file to your python35/Scripts directory
Open a command prompt in the Scripts directory (Shift-Right click in the directory > Open a command window here)
Enter the command:
pip3 install pygame-1.9.2a0-cp35-none-win32.whl
If you get an error in the last step, try:
python -m pip install pygame-1.9.2a0-cp35-none-win32.whl
And that should do it. Tested as working on Windows 10 64bit.
I was trying to figure this out for at least an hour. And you're right the problem is that the installation files are all for 32 bit.
Luckily I found a link to the 64 pygame download! Here it is: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
Just pick the corresponding version according to your python version and it should work like magic. The installation feature will bring you to a bright-blue screen as the installation (at this point you know that the installation is correct for you.
Then go into the Python IDLE and type "import pygame" and you should not get any more errors.
Props go to #yuvi who shared the link with StackOverflow.
open the folder where your python is installed
open scripts folder
type cmd in the address bar. It opens a command prompt window in that location
type pip install pygame and press enter
it should download and install pygame module
now run your code. It works fine :-)
I had the same problem and discovered that Pygame doesn't work for Python3 at least on the Mac OS, but I also have Tython2 installed in my computer as you probably do too, so when I use Pygame, I switch the path so that it uses python2 instead of python3. I use Sublime Text as my text editor so I just go to
Tools > Build Systems > New Build System and enter the following:
{
"cmd": ["/usr/local/bin/python", "-u", "$file"],
}
instead of
{
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
}
in my case. And when I'm not using pygame, I simply change the path back so that I can use Python3.
The current PyGame release, 1.9.6 doesn't support Python 3.9. I fyou don't want to wait for PyGame 2.0, you have to use Python 3.8. Alternatively, you can install a developer version by explicitly specifying the version (2.0.0.dev20 is the latest release at the time of writing):
pip install pygame==2.0.0.dev20
or try to install a pre-release version by enabling the --pre option:
pip install pygame --pre
Resolved !
Here is an example
C:\Users\user\AppData\Local\Programs\Python\Python36-32\Scripts>pip install pygame
try this in your command prompt:
python -m pip install pygame
I was getting the same error. It is because your version of Pygame is not compatible with your version of Python or Pydev. Go to this link and get the proper version of Pygame for your current version of Python. Ctrl F to find it faster or click on the word python in blue. up at the top. While you instal Pygame it should find the Python path by itself. At least mind did any ways. I run Pygame through Eclipse with Python 3.4.
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Since no answer stated this:
Make sure that, if you are using a virtual environment, you have activated it before trying to run the program.
If you don't really know if you are using a virtual environment or not, check with the other contributors of the project. Or maybe try to find a file with the name activate like this: find . -name activate.
Install and download pygame .whl file.
Move .whl file to your python35/Scripts
Go to cmd
Change directory to python scripts
Type:
pip install pygame
Here is an example:
C:\Users\user\AppData\Local\Programs\Python\Python36-32\Scripts>pip install pygame
I just encountered the same problem and found that I am having multiple interpreters of the different versions installed in my system and pygame got installed in one of them when I installed it using command but in my IDE another interpreter was selected so this messed up my system, try to see if you are also having the same situation.
Just use this command in the terminal python3 -m pip install -U pygame --user
I am a quite newbie to python and I was having same issue. (windows x64 os)
I have solved, doing below steps
I removed python (x64 version) and pygame
I have downloaded and installed python 2.6.6 x86: https://www.python.org/ftp/python/2.6.6/python-2.6.6.msi
I have downloaded and installed pygame (when installing, I have chosen the directory that I installed python): http://pygame.org/ftp/pygame-1.9.1.win32-py2.6.msi
Works well :)
You don't need 64 bit Python on Win64 system, just install the 32bit versions of both Python and Pygame and they will work just fine (and there is a ton more modules for them anyways).
I’m using the PyCharm IDE. I could get Pygame to work with IDLE but not with PyCharm. This video helped me install Pygame through PyCharm.
https://youtu.be/HJ9bTO5yYw0
(It seems that PyCharm only recognizes a package; if you use its GUI.)
However, there were a few slight differences for me; because I’m using Windows instead of a Mac.
My “preferences” menu is found in: File->Settings…
Then, in the next screen, I expanded my project menu, and clicked Project Interpreter. Then I clicked the green plus icon to the right to get to the Available Packages screen.
I ran into the error a few days ago! Thankfully, I found the answer.
You see, the problem is that pygame comes in a .whl (wheel) file/package. So, as a result, you have to pip install it.
Pip installing is a very tricky process, so please be careful. The steps are:-
Step1. Go to C:/Python (whatever version you are using)/Scripts. Scroll down. If you see a file named pip.exe, then that means that you are in the right folder. Copy the path.
Step2. In your computer, search for Environment Variables. You should see an option labeled 'Edit the System Environment Variables'. Click on it.
Step3. There, you should see a dialogue box appear. Click 'Environment Variables'. Click on 'Path'. Then, click 'New'. Paste the path that you copies earlier.
Step4. Click 'Ok'.
Step5. Shift + Right Click wherever your pygame is installed. Select 'Open Command Window Here' from the dropdown menu. Type in 'pip install py' then click tab and the full file name should fill in. Then, press Enter, and you're ready to go! Now you shouldn't get the error again!!!
First execute python3 then type the command import pygame,now you can see the output
For this you have to install pygame package from the cmd (on Windows) or from terminal (on mac). Just type pip install pygame
.If it doesn't work for you, then try using this statement pip3 install pygame .
If it is still showing an error then you don't have pip installed on your device and try installing pip first.
make sure if you are on windows that your library directory is added to path
This may happen when pygame didn't installed, install the pygame first
pip
pip install pygame
if dont work update the PIP by goto python install folder and type
python -m pip install --upgrade pip
hope it work
Try this solution:
Type in to cmd (Windows):
C:\Users\'Your name'> pip install -U pygame
You should remove python -m, py -m, python3 -m before the pip
Also remove --user behind it.
It will said:
C:\Users\viait>pip install -U pygame
Defaulting to user installation because normal site-packages is not writeable
Collecting pygame
Downloading pygame-2.1.2-cp310-cp310-win_amd64.whl (8.4 MB)
---------------------------------------- 8.4/8.4 MB 1.7 MB/s eta 0:00:00
Installing collected packages: pygame
Successfully installed pygame-2.1.2
Then test it in your IDE or cmd:
(CMD example)
C:\Users\viait>python
Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 2.1.2 (SDL 2.0.18, Python 3.10.3)
Hello from the pygame community. https://www.pygame.org/contribute.html
(IDE example)
import pygame
You can do this without any errors.
You could use
pip install pygame
but if you use IDE like PyCharm, then you could just either install it from Python Packages or use right click at the package name then left click on Show Context Actions then left click on Install package pygame
(Personally, I recommended using Python Packages for the package installing because it has documentation with it)
You gotta use Pycharm and install it in Terminal using pip install pygame and also after that enter Pycharm and hover on pygame in the "Import pygame" and in Pycharm it will tell you to download that and you can easily download it and enjoy your result
I was having the same trouble and I did
pip install pygame
and that worked for me!

How to install wheel packages

I am trying to install PocketSphinx in Python. I am trying to follow the Uberi speech recognition README, which asks the following:
PyAudio wheel packages for
common 64-bit Python versions on Windows and Linux are included for
convenience, under the third-party/
directory
in the repository root. To install, simply run pip install wheel
followed by pip install ./third-party/WHEEL_FILENAME (replace pip
with pip3 if using Python 3) in the repository root
directory.
I do not understand the instruction here. What FILE_NAME is this referring to? What is this wheel and how does it relate to PocketSphinx?
When you downloaded the PocketSphinx package manually, it must have created a wheel file (the file which does the real job) with a .whl extension in the said directory.
Now, you need to open a terminal in the directory where the .whl extension file is stored, which in this case is third-party.
Once you make sure that the terminal shows the current directory as third-party, go ahead and do a pip install of the wheel file.
Assuming the name of the wheel file to be PocketSphinx.whl,
You'd write:
pip install PocketSphinx.whl
This will do your job if all requirements are met.
And I have a feeling that the name of the wheel file wouldn't be simply PocketSphinx.whl, it'll be long and informative, nonetheless it will always have the extension .whl, by which you shall identify it.
Edit:
I went to the link you provided, and this is the wheel file you need:
pocketsphinx-0.1.3-cp35-cp35m-win_amd64.whl for python 3.5
Or
pocketsphinx-0.1.3-cp27-cp27m-win_amd64.whl for python 2.7
So your command becomes
pip install pocketsphinx-0.1.3-cp35-cp35m-win_amd64.whl
Or
pip install pocketsphinx-0.1.3-cp27-cp27m-win_amd64.whl
As per your python version.
What FILE_NAME is this referring to?
Filename of the binary package file in third-party folder of the repository. For example pocketsphinx-0.0.9-cp27-none-win_amd64.whl. You are supposed to checkout repository first.
What is this 'wheel' and how does it relate to pocketsphix?
wheel is a python package manager to install binary packages. It is used to install python binary package. You can read more here: https://pypi.python.org/pypi/wheel

Python (Win 10): Installing matplotlib requires packages "freetype" and "png"?

I've been trying to install Python's matplotlib library for use with PyPlot, for use with Julia. I managed to get everything in place except for this one final library, and I feel as though I've hit a deadend trying to get it working.
When trying to install matplotlib (I've attempted using pip, regular python install, and easy_install), I get the following message at the very end of the install output, after which it is NOT installed:
* The following required packages can not be built:
* freetype, png
Confused about this, I looked around online and installed both of these (at least, what I think these were). One was the freetype project, and the other was LibPng, which was the closest thing I could find to a "png package" for windows or python in general.
This didn't initially work (for either of them), and I read somewhere that I needed a freetype.dll in my system32 folder. It was a long shot, but I went to where I installed freetype and pulled out the dll and renamed it, placing it in system32. This of course did not work (again, long shot).
Anyway, that's where I'm at. No idea where to go from here, and I'm unsure if I even grabbed the correct "packages" I should be using. Thoughts?
Use a more powerful installer
I would recommend to use Anaconda or Miniconda. In my experience with many Windows users, this is the simplest way to install packages such as matplotlib.
Anaconda
Anaconda comes with many packages for scientists. Matplotlib works out of the box. Just install as user not root.
Minoconda
If you don't want all packages of Ananconda use Miniconda
Conda
Both ways of installation (Anaconda or Miniconda) provide conda. It is an improved pip/virtualenv.
You can install matplotilb with this command:
conda install matplotlib
Enviroments:
You can create a new environment and install the packages you like:
conda create -n my_project35 python=3.5
activate my_project35
conda install matplotlib
or
conda create -n my_project27 python=2.7
activate my_project27
conda install matplotlib
Combine with pip
You can still use pip. conda "understands" what it is doing.
One snake is enough!
[This is for folks using the Linux Bash Shell on Windows 10.]
If you don't want to go the Anaconda route, you can install freetype (and png) by executing the following in the Windows 10 Bash shell:
sudo apt-get install freetype6-dev
The above command will also automatically install libpng. However, due to an error, the system will not 'realize' it has installed freetype, so you'll need to manually install pkg-config:
sudo apt-get install pkg-config
Thereafter you should be able to install matplotlib via pip without further incident.
sudo pip install matplotlib
I tired downloading matplotlib 2.2.2 with python 3.9.5, getting freetype & png errors for hours.
After downloading python 3.7.9 and removing python 3.9.5 from environment variables, installing matplotlib 2.2.2 worked with no problems!
Change your Python Version
Go to https://www.python.org/downloads/windows/, control-f search 3.7.9 and use the webinstaller. Follow all the recommended instructions
In pyvenv.cfg in your project directory switch version number to 3.7.9 and home to C:.....\Python37.
pip3 install alpaca-backtrader-api

How do I open a .whl binary installation file in CMD? Win Py 2.7 Err "No distributions at all found for lxml-3.4.4-cp27-none-win32.whl"

I've been at this for nearly 2 hours and I just can't seem to get my head around it. I am a novice Pythoner, it would appear. I am trying to intsall lxml, (needed to install scrapy). I have tried multiple methods (see my other current quesitons).
Currently I am trying the following.
I downloaded the lxml win 32 file for python 2.7 from this website:
https://pypi.python.org/pypi/lxml/3.4.4#downloads
The LXML Binaries are also available here: "http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml"
I download the .whl file.
I then open up CMD, and CD to my download folder. Once in that folder I run the following command (as per the answer to this question here: How do I install a Python package with a .whl file?)
pip install lxml-3.4.4-cp27-none-win32.whl
This is the output:
C:\Users\Charles\Downloads\python>pip install lxml-3.4.4-cp27-none-win32.whl
Downloading/unpacking lxml-3.4.4-cp27-none-win32.whl
Could not find any downloads that satisfy the requirement lxml-3.4.4-cp27- none
-win32.whl
No distributions at all found for lxml-3.4.4-cp27-none-win32.whl
Storing complete log in C:\Users\Charles\AppData\Roaming\pip\pip.log
Can anyone help me figure out what this means/what is going on? How can I execute this file to install the lxml as needed?
Many thanks!!
Edit: I am using Windows 64 bit, but from this question here: "easy_install lxml on Python 2.7 on Windows" the file I have selected appears to be the correct one.
I am using Windows 64 bit and use Scrapy. It took a while for me to figure out the best way to set up my virtualenv because lxml would not simply pip install.
So I did somethine very similar to what you did but it looks at first glance we may just be using different sites. So try downloading this .whl from HERE. Specifically, for your specifications I believe, grab the one that reads
lxml-3.4.4-cp27-none-win_amd64.whl
and then just cd to the downloads folder and pip install lxml-3.4.4-cp27-none-win_amd64.whl
The first thing you should do is upgrade pip; the latest version is 8.0. Next, you need to install wheel support (this step may be redundant in later versions) and then finally install your wheel:
pip install --upgrade pip
pip install wheel
lxml needs a lot of source-level dependencies, which are difficult to install in Windows. This is why the project provides binary installers for Windows. You can download these from the pypi page for lxml. Make sure you choose the right version for your environment:
lxml-3.4.4.win32-py2.7.exe - for Python 2.7 running on Windows 32-bit
lxml-3.4.4.win32-py3.2.exe - for Python 3.2 running on Windows 32-bit
lxml-3.4.4.win-amd64-py2.7.exe - for Python 2.7, running on Windows 64-bit

How to use -pip- to install packages that can work with Anaconda?

I am trying to install some additional packages that do not come with Anaconda. All of these packages can be installed using pip install PackageName. However, when I type this command at the Anaconda Command Prompt, I get the following error:
Fatal error in launcher: Unable to create process using '"C:\Python27\python.exe
" "C:\python27\scripts\pip.exe" install MechanicalSoup'
I also tried to run the command from the python interpreter after import pip but that also did not work (I got a SyntaxError: invalid syntax).
I am a noob and understand that this might be a very basic question so thanks for your help in advance!
PS: I am using Windows 7, 64 bit, conda version: 3.7.1 and python version: 2.7.6.
When installing anaconda, you are asked if you want to include the installed python to your system PATH variable. Make sure you have it in your PATH. If everything is set up correct, you can run pip from your regular command prompt aswell.
Using #heinzchr's and #mmann's suggestions I was able to piece together the problem. I already had a version of Python 2.7 saved at C:\Python27 and I had to remove this from the Path (My Computer's properties> Advanced system settings> System variables> Path). I can now use pip install from the command line.
There is a way around the use of pip
From the anaconda terminal window you can run:
conda install PackageName
Because MechanicalSoup isn't in one of anaconda's package channels you will have to do a bit of editing
See instructions near the bottom on their blog
For those looking for Python packages not added to current channels in anaconda, try https://conda-forge.org/ For example, if you want to install MechanicalSoup you'll find it at https://anaconda.org/conda-forge/mechanicalsoup and use the -c option to tell conda the channel to use:
conda install -c conda-forge mechanicalsoup