How can I install numpy and pandapower?
How can I install numpy and pandapower on the RASPBIAN JESSIE LITE Minimal image based on Debian Jessie? the one without the GUI. And how can I install Pip and miniconda on it as well?
2 Answers 2
By default, Jessie Lite for Raspberry Pi have python 2.7 installed but does not have pip/setuptools/wheel installed. To install pip, run:
This will install setup tools and wheel along with pip.
You can then use pip to install packages you will need. To install NumPy:
I recommend using the —user flag to pip (without using sudo pip ). This will install packages for your local user, and does not need extra permissions to write to the system directories.
I recommend installing numpy via apt-get not via pip as the latter needs to compile the lib on the Pi and that is no fun. Not sure about pandas but I would expect something similar. So use:
With program name being something like ‘python-numpy’.
Pip on the other hand should already be installed if Python is available.
Update:
The MagPi, Issue 64 reports about piwheels:
Pi Foundation Community Manager Ben Nuttall has released piwheels, a set of pre-compiled Python modules that reduces the install time from tens of minutes to a couple of seconds. Pip is the best way to install Python packages, as it grabs the very latest version. However, often these packages “have been implemented in C and require compilation,” Ben explains. Compilation takes ages, however – installing the NumPy package on a Pi 3 can take over 20 minutes.
The Python community solved this problem a while back with ‘wheels’, pre-compiled versions of packages for common hardware and software combinations. However, until Ben’s project, there were no wheels for a Pi running Raspbian. Enter Ben with his epic project to pre-compile all 750,000 wheels for the Raspberry Pi. With some help from SQL expert Dave Jones (@waveform80), and the Raspberry Pi Foundation’s web host Mythic Beasts (mythic-beasts.com), there are now over 670,000 wheels for more than 96,000 packages. NumPy now installs in seconds using the command sudo pip3 install numpy.
So now one could use pip to install numpy and pandas without long compilation times simply by:
Scientific Python for Raspberry Pi
By gboeing
Post date
A guide to setting up the Python scientific stack, well-suited for geospatial analysis, on a Raspberry Pi 3. The whole process takes just a few minutes.
The Raspberry Pi 3 was announced two weeks ago and presents a substantial step up in computational power over its predecessors. It can serve as a functional Wi-Fi connected Linux desktop computer, albeit underpowered. However it’s perfectly capable of running the Python scientific computing stack including Jupyter, pandas, matplotlib, scipy, scikit-learn, and OSMnx.
Despite (or because of?) its low power, it’s ideal for low-overhead and repetitive tasks that researchers and engineers often face, including geocoding, web scraping, scheduled API calls, or recurring statistical or spatial analyses (with small-ish data sets). It’s also a great way to set up a simple server or experiment with Linux. This guide is aimed at newcomers to the world of Raspberry Pi and Linux, but who have an interest in setting up a Python environment on these $35 credit card sized computers. We’ll run through everything you need to do to get started (if your Pi is already up and running, skip steps 1 and 2).
Step 1: Get the hardware
Assuming you have an available phone charger, HDMI cable, mouse, and keyboard, you can buy everything else you need to get up and running for under $45. Here’s what you’ll need:
- A Raspberry Pi ($35)
- A 5-volt 1-amp power supply (I just used an old Android charger with a micro-USB cable, otherwise about $5)
- A micro SD card with a full-size SD adapter (about $9)
- An HDMI cable to connect your monitor (I already had one, otherwise about $5)
- USB mouse/keyboard (I already had them, otherwise about $15 for a basic set)
- Optional: if you’re running your Raspberry Pi side-by-side with a desktop computer, you can get a cheap USB switch to switch your mouse/keyboard from the computer to the Raspberry Pi and back
Step 2: Install Raspbian OS on the Raspberry Pi
Now we’ll install Raspbian (the Debian Linux OS tailored for Raspberry Pi) the easy way, then boot the OS and connect to Wi-Fi.
- Pop your micro SD card into its full-size SD adapter sleeve and stick it in your computer
- Download the NOOBS installer for Raspbian and un-zip it to your desktop
- Download SDFormatter and install it (this tool is particularly useful if you eventually want to refresh your Raspberry Pi system, as the Linux partitions otherwise might be tricky to work with on your desktop computer)
- Open SDFormatter, choose the SD card drive, click format
- When the formatting is done, copy the NOOBS files from your desktop to the SD card
- Pop the SD card out of the adapter sleeve and into the Raspberry Pi
- Connect your mouse, keyboard, HDMI, and power supply to the Raspberry Pi
- Once NOOBS boots up, choose your language, select Raspbian, then click install
When the installation is finished, click ok and the new OS will boot up. The Raspberry Pi 3 has Wi-Fi: in the top-right of the screen, click the Wi-Fi networks panel item and choose your network to connect.
Step 3: Update packages
Next we update the existing software. Open a terminal window and run the following commands, one at a time. The first line fetches updated package lists from the repositories, and the second then fetches new versions of installed packages. The last two lines list the installed system packages and installed Python packages and dump them to files, just for reference.
apt-get is a Debian tool to install and update software packages. We’ll use it instead of pip wherever we can because the packages come pre-compiled, meaning they take seconds rather than minutes to install. When a Python package isn’t available via apt-get, we’ll fall back on using pip to install (and compile) it.
Step 4: Install the Python basics
As we saw in the previous step’s file output, the Raspberry Pi comes with several Python packages already installed. We need to supplement it with a few more prerequisites. In the terminal window, run this command:
The build-essential package is required for building Debian packages; python-dev, python-distlib, and python-setuptools provide several Python development and packaging tools; python-pip and python-wheel are useful for installing Python packages; libzmq-dev is needed for Jupyter notebooks; libgdal-dev is needed for geospatial analysis with geopandas.
Step 5: Install pandas dependencies
Pandas has several recommended and optional dependencies that unlock functionality or provide significant performance enhancements. To install them all, run the following two commands:
The first command uses apt-get to install the available recommended dependencies, and the second command uses pip to install the two that are not available in the apt repositories.
Step 6: Install the scientific Python stack
Fortunately we can use apt-get to install all the massive, complex packages that make up the Python scientific stack without having to compile everything. This makes the process much, much faster.
If you need a specific version of these packages or want a more up-to-date version than exists in the Debian repositories, you can use pip to install it, but be prepared for a slow compilation process.
Step 7 (optional): Install other useful packages
We’re all done! But if you optionally would like to install a few more useful packages, run the following two commands:
The requests Python package provides a graceful interface for making HTTP requests, pil provides Python imaging capabilities, scrapy is a web scraping framework, geopy provides geocoding and geodesic distance functions, shapely provides 2D geometry manipulation, and pyproj provides cartographic transformations. In the second command, jupyter provides interactive coding notebooks, geopandas spatializes pandas, and OSMnx lets you work with OpenStreetMap street networks.
Wrapping up
Our Python scientific stack is now all ready to use on the Raspberry Pi. Launch a Jupyter notebook, load up some data with pandas, or plot a map with basemap. Due to the Raspberry Pi’s memory constraints, you cannot load huge data sets, but everything else works great. It’s particularly good for repetitive, scheduled, or low-overhead tasks such as geocoding and web scraping.
How do I successfully install PyTorch (numpy, pandas and scipy) on Raspberry pi 4? And briefly discuss the performance of raspberry pi after upgrading to ubuntu 64bit
I recently read about installing a 64-bit operating system for the Raspberry Pi 4. This is the original link.
Before that, my raspberry pi 4 was almost deserted due to performance reasons and complicated building process. However, when I installed the 64-bit system and tested its performance, I could hardly believe my eyes. The CPU test results of sysbench increased by 15 times. The number of events processed per second has increased from 120 to almost 1900.
It is worth noting here that I overclocked the Raspberry Pi to 1.9GHz for better performance, and the standby temperature was maintained at about 40 degrees Celsius.
Here is the code I run for test:
If you are interested in single-core CPU performance, you can use the following command to test:
After that, I discovered that the Raspberry Pi 4 has great potential in computing. So I decided to install a series of machine learning packages such as PyTorch for it.
Below I will briefly describe installing from source and my pre-built packages.
Install PyTorch from source
PyTorch does not provide a specific installation package for the arm64 system. The only way is to build it from the source step by step. Prior to that, I read an article ‘A Step by Step guide to installing PyTorch in Raspberry Pi’, however after I tried several times, I found that I could successfully install PyTorch, but I couldn’t use it successfully. This is because the python wheel mentioned in the article is for Jetson Nano, not raspberry pi. Although they all use Arm, Jetson Nano has Cuda core which raspberry pi does not.
Step 1: Add extra SWAP memory
Installing PyTorch was extremely memory intensive and I added 2GB of SWAP to my raspberry pi 4GB memory version. Even so, during the compilation process, 5GB + memory consumption sometimes occurs. For those with tight memory resources, I provide a pre-built wheel package at the back, which you can easily install and use.
After that, add the following code into the end of /etc/fstab.
Then restart the system and observe if the SWAP is successfully added through the htop command.
Step 2: Download the code
I tried installing PyTorch 1.4, but it produced errors during the pre-build process. I don’t think this is my problem, because I find that other people who try to build by themselves have the same problem. So I installed the 1.3.1 version, which is completely enough for me.
Step 3: Build the wheel
Before that, we need to set some environment variables.
At the same time, we may need to install some necessary system packages. I may omit some packages here, but these are minor problems and solutions can be searched directly through Google.
After doing the preparations, start building the wheel:
The whole process takes about 2~3 hours. When the build is complete, the wheel file can be found in the pytorch/dist folder.
Use pip to install the wheel at last.
Install PyTorch from the pre-build wheel
Only 1 step
I uploaded my pre-built PyTorch wheel to my GitHub. You can download it directly via wget:
This takes about a few minutes to complete.
Finally, test by importing it:
However, please note that PyTorch requires support from other packages, such as numpy. You may need to install numpy first. After testing, this will also cost you a lot of time. The wheels of numpy, pandad, matplotlib and torchvision are also provided in my GitHub.
I will update the wheel in my free time, or you can pull request. So that more people can enjoy the Raspberry Pi. And please feel free to comment.
Python 3: ModuleNotFoundError: No module named ‘pandas.util’ (raspberry pi)
Am having issues importing pandas on python3 on my raspberry pi. Whatever I try, I get the following error:
It works fine on Python 2.7. I am getting errors with Python 3.7.3.
I searched Google and tried everything in the following post:
Some of the things I’ve tried are below — none have helped — I still get the error.
I’ve also tried uninstalling and reinstalling numpy and pandas — still get this error just with a basic import statement.
Any help would be appreciated as this is driving me insane!!
1 Answer 1
This will ensure two things:
- it will use the pip executable that belongs to the used Python executable, so that there is no accidental installation by another pip.
- it will properly re-install Pandas.
Note that it doesn’t re-download the Pandas package (it will use a cached version) if the version on PyPI hasn’t changed between now and the previous installation. If that is a potential problem (incorrect cached file, for example), add the option —no-cache-dir to pip install .
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2022.10.6.30587
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Scientific Python for Raspberry Pi
By gboeing
Post date
A guide to setting up the Python scientific stack, well-suited for geospatial analysis, on a Raspberry Pi 3. The whole process takes just a few minutes.
The Raspberry Pi 3 was announced two weeks ago and presents a substantial step up in computational power over its predecessors. It can serve as a functional Wi-Fi connected Linux desktop computer, albeit underpowered. However it’s perfectly capable of running the Python scientific computing stack including Jupyter, pandas, matplotlib, scipy, scikit-learn, and OSMnx.
Despite (or because of?) its low power, it’s ideal for low-overhead and repetitive tasks that researchers and engineers often face, including geocoding, web scraping, scheduled API calls, or recurring statistical or spatial analyses (with small-ish data sets). It’s also a great way to set up a simple server or experiment with Linux. This guide is aimed at newcomers to the world of Raspberry Pi and Linux, but who have an interest in setting up a Python environment on these $35 credit card sized computers. We’ll run through everything you need to do to get started (if your Pi is already up and running, skip steps 1 and 2).
Step 1: Get the hardware
Assuming you have an available phone charger, HDMI cable, mouse, and keyboard, you can buy everything else you need to get up and running for under $45. Here’s what you’ll need:
- A Raspberry Pi ($35)
- A 5-volt 1-amp power supply (I just used an old Android charger with a micro-USB cable, otherwise about $5)
- A micro SD card with a full-size SD adapter (about $9)
- An HDMI cable to connect your monitor (I already had one, otherwise about $5)
- USB mouse/keyboard (I already had them, otherwise about $15 for a basic set)
- Optional: if you’re running your Raspberry Pi side-by-side with a desktop computer, you can get a cheap USB switch to switch your mouse/keyboard from the computer to the Raspberry Pi and back
Step 2: Install Raspbian OS on the Raspberry Pi
Now we’ll install Raspbian (the Debian Linux OS tailored for Raspberry Pi) the easy way, then boot the OS and connect to Wi-Fi.
- Pop your micro SD card into its full-size SD adapter sleeve and stick it in your computer
- Download the NOOBS installer for Raspbian and un-zip it to your desktop
- Download SDFormatter and install it (this tool is particularly useful if you eventually want to refresh your Raspberry Pi system, as the Linux partitions otherwise might be tricky to work with on your desktop computer)
- Open SDFormatter, choose the SD card drive, click format
- When the formatting is done, copy the NOOBS files from your desktop to the SD card
- Pop the SD card out of the adapter sleeve and into the Raspberry Pi
- Connect your mouse, keyboard, HDMI, and power supply to the Raspberry Pi
- Once NOOBS boots up, choose your language, select Raspbian, then click install
When the installation is finished, click ok and the new OS will boot up. The Raspberry Pi 3 has Wi-Fi: in the top-right of the screen, click the Wi-Fi networks panel item and choose your network to connect.
Step 3: Update packages
Next we update the existing software. Open a terminal window and run the following commands, one at a time. The first line fetches updated package lists from the repositories, and the second then fetches new versions of installed packages. The last two lines list the installed system packages and installed Python packages and dump them to files, just for reference.
apt-get is a Debian tool to install and update software packages. We’ll use it instead of pip wherever we can because the packages come pre-compiled, meaning they take seconds rather than minutes to install. When a Python package isn’t available via apt-get, we’ll fall back on using pip to install (and compile) it.
Step 4: Install the Python basics
As we saw in the previous step’s file output, the Raspberry Pi comes with several Python packages already installed. We need to supplement it with a few more prerequisites. In the terminal window, run this command:
The build-essential package is required for building Debian packages; python-dev, python-distlib, and python-setuptools provide several Python development and packaging tools; python-pip and python-wheel are useful for installing Python packages; libzmq-dev is needed for Jupyter notebooks; libgdal-dev is needed for geospatial analysis with geopandas.
Step 5: Install pandas dependencies
Pandas has several recommended and optional dependencies that unlock functionality or provide significant performance enhancements. To install them all, run the following two commands:
The first command uses apt-get to install the available recommended dependencies, and the second command uses pip to install the two that are not available in the apt repositories.
Step 6: Install the scientific Python stack
Fortunately we can use apt-get to install all the massive, complex packages that make up the Python scientific stack without having to compile everything. This makes the process much, much faster.
If you need a specific version of these packages or want a more up-to-date version than exists in the Debian repositories, you can use pip to install it, but be prepared for a slow compilation process.
Step 7 (optional): Install other useful packages
We’re all done! But if you optionally would like to install a few more useful packages, run the following two commands:
The requests Python package provides a graceful interface for making HTTP requests, pil provides Python imaging capabilities, scrapy is a web scraping framework, geopy provides geocoding and geodesic distance functions, shapely provides 2D geometry manipulation, and pyproj provides cartographic transformations. In the second command, jupyter provides interactive coding notebooks, geopandas spatializes pandas, and OSMnx lets you work with OpenStreetMap street networks.
Wrapping up
Our Python scientific stack is now all ready to use on the Raspberry Pi. Launch a Jupyter notebook, load up some data with pandas, or plot a map with basemap. Due to the Raspberry Pi’s memory constraints, you cannot load huge data sets, but everything else works great. It’s particularly good for repetitive, scheduled, or low-overhead tasks such as geocoding and web scraping.