install numpy for pycharm on mac
I’m completely new to Python, and just downloaded Anaconda with a professional license. I then cloned a GitHub repository into PyCharm to work on as my first project. PyCharm (which I’ve never used before) fails on the first line of code:
import numpy as np Traceback (most recent call last): File "", line 1, in File "/Applications/PyCharm with Anaconda plugin .app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) ModuleNotFoundError: No module named 'numpy'
My understanding is that Anaconda should have «shipped» with numpy, scipy, and some other key packages. I get that PyCharm isn’t finding that somehow, but how do I redirect it? I’m using a Mac and PyCharm 2020.1. Some of the other help pages said to install packages from the «settings» tab or file/default settings, but neither of those buttons exist in this version of the IDE. I also tried installing numpy in the Python console box based on this solution but that didn’t work either:
pip3 install numpy File "", line 1 pip3 install numpy ^
How do I get PyCharm to «find» the software that I supposedly downloaded with Anaconda? Edit: I managed to open the python interpreter for this project and install numpy with the «+» button, but it still gives this error when I run import numpy as np :
>>> import numpy as np Traceback (most recent call last): File "", line 1, in File "/Applications/PyCharm with Anaconda plugin .app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) ModuleNotFoundError: No module named 'numpy'
Edit 2: this error went away after restarting PyCharm. I’m surprised that’s necessary after installing a package.
Installing NumPy
The only prerequisite for installing NumPy is Python itself. If you don’t have Python yet and want the simplest way to get started, we recommend you use the Anaconda Distribution — it includes Python, NumPy, and many other commonly used packages for scientific computing and data science.
NumPy can be installed with conda , with pip , with a package manager on macOS and Linux, or from source. For more detailed instructions, consult our Python and NumPy installation guide below.
CONDA
If you use conda , you can install NumPy from the defaults or conda-forge channels:
# Best practice, use an environment rather than install in the base env conda create -n my-env conda activate my-env # If you want to install from conda-forge conda config --env --add channels conda-forge # The actual install command conda install numpy
PIP
If you use pip , you can install NumPy with:
pip install numpy
Also when using pip, it’s good practice to use a virtual environment — see Reproducible Installs below for why, and this guide for details on using virtual environments.
Python and NumPy installation guide
Installing and managing packages in Python is complicated, there are a number of alternative solutions for most tasks. This guide tries to give the reader a sense of the best (or most popular) solutions, and give clear recommendations. It focuses on users of Python, NumPy, and the PyData (or numerical computing) stack on common operating systems and hardware.
Recommendations
We’ll start with recommendations based on the user’s experience level and operating system of interest. If you’re in between “beginning” and “advanced”, please go with “beginning” if you want to keep things simple, and with “advanced” if you want to work according to best practices that go a longer way in the future.
Beginning users
On all of Windows, macOS, and Linux:
- Install Anaconda (it installs all packages you need and all other tools mentioned below).
- For writing and executing code, use notebooks in JupyterLab for exploratory and interactive computing, and Spyder or Visual Studio Code for writing scripts and packages.
- Use Anaconda Navigator to manage your packages and start JupyterLab, Spyder, or Visual Studio Code.
Advanced users
Conda
- Install Miniforge.
- Keep the base conda environment minimal, and use one or more conda environments to install the package you need for the task or project you’re working on.
Alternative if you prefer pip/PyPI
For users who know, from personal preference or reading about the main differences between conda and pip below, they prefer a pip/PyPI-based solution, we recommend:
- Install Python from python.org, Homebrew, or your Linux package manager.
- Use Poetry as the most well-maintained tool that provides a dependency resolver and environment management capabilities in a similar fashion as conda does.
Python package management
Managing packages is a challenging problem, and, as a result, there are lots of tools. For web and general purpose Python development there’s a whole host of tools complementary with pip. For high-performance computing (HPC), Spack is worth considering. For most NumPy users though, conda and pip are the two most popular tools.
Pip & conda
The two main tools that install Python packages are pip and conda . Their functionality partially overlaps (e.g. both can install numpy ), however, they can also work together. We’ll discuss the major differences between pip and conda here — this is important to understand if you want to manage packages effectively.
The first difference is that conda is cross-language and it can install Python, while pip is installed for a particular Python on your system and installs other packages to that same Python install only. This also means conda can install non-Python libraries and tools you may need (e.g. compilers, CUDA, HDF5), while pip can’t.
The second difference is that pip installs from the Python Packaging Index (PyPI), while conda installs from its own channels (typically “defaults” or “conda-forge”). PyPI is the largest collection of packages by far, however, all popular packages are available for conda as well.
The third difference is that conda is an integrated solution for managing packages, dependencies and environments, while with pip you may need another tool (there are many!) for dealing with environments or complex dependencies.
Reproducible installs
As libraries get updated, results from running your code can change, or your code can break completely. It’s important to be able to reconstruct the set of packages and versions you’re using. Best practice is to:
- use a different environment per project you’re working on,
- record package names and versions using your package installer; each has its own metadata format for this:
- Conda: conda environments and environment.yml
- Pip: virtual environments and requirements.txt
- Poetry: virtual environments and pyproject.toml
NumPy packages & accelerated linear algebra libraries
NumPy doesn’t depend on any other Python packages, however, it does depend on an accelerated linear algebra library — typically Intel MKL or OpenBLAS. Users don’t have to worry about installing those (they’re automatically included in all NumPy install methods). Power users may still want to know the details, because the used BLAS can affect performance, behavior and size on disk:
- The NumPy wheels on PyPI, which is what pip installs, are built with OpenBLAS. The OpenBLAS libraries are included in the wheel. This makes the wheel larger, and if a user installs (for example) SciPy as well, they will now have two copies of OpenBLAS on disk.
- In the conda defaults channel, NumPy is built against Intel MKL. MKL is a separate package that will be installed in the users’ environment when they install NumPy.
- In the conda-forge channel, NumPy is built against a dummy “BLAS” package. When a user installs NumPy from conda-forge, that BLAS package then gets installed together with the actual library — this defaults to OpenBLAS, but it can also be MKL (from the defaults channel), or even BLIS or reference BLAS.
- The MKL package is a lot larger than OpenBLAS, it’s about 700 MB on disk while OpenBLAS is about 30 MB.
- MKL is typically a little faster and more robust than OpenBLAS.
Besides install sizes, performance and robustness, there are two more things to consider:
- Intel MKL is not open source. For normal use this is not a problem, but if a user needs to redistribute an application built with NumPy, this could be an issue.
- Both MKL and OpenBLAS will use multi-threading for function calls like np.dot , with the number of threads being determined by both a build-time option and an environment variable. Often all CPU cores will be used. This is sometimes unexpected for users; NumPy itself doesn’t auto-parallelize any function calls. It typically yields better performance, but can also be harmful — for example when using another level of parallelization with Dask, scikit-learn or multiprocessing.
Troubleshooting
If your installation fails with the message below, see Troubleshooting ImportError.
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy c-extensions failed. This error can happen for different reasons, often due to issues with your setup.
Install#
NetworkX requires Python 3.9, 3.10, or 3.11. If you do not already have a Python environment configured on your computer, please see the instructions for installing the full scientific Python stack.
Below we assume you have the default Python environment already configured on your computer and you intend to install networkx inside of it. If you want to create and work with Python virtual environments, please follow instructions on venv and virtual environments.
First, make sure you have the latest version of pip (the Python package manager) installed. If you do not, refer to the Pip documentation and install pip first.
Install the released version#
Install the current release of networkx with pip :
$ pip install networkx[default]
To upgrade to a newer release use the —upgrade flag:
$ pip install --upgrade networkx[default]
If you do not have permission to install software systemwide, you can install into your user directory using the —user flag:
$ pip install --user networkx[default]
If you do not want to install our dependencies (e.g., numpy , scipy , etc.), you can use:
$ pip install networkx
This may be helpful if you are using PyPy or you are working on a project that only needs a limited subset of our functionality and you want to limit the number of dependencies.
Alternatively, you can manually download networkx from GitHub or PyPI. To install one of these versions, unpack it and run the following from the top-level source directory using the Terminal:
$ pip install .[default]
Install the development version#
If you have Git installed on your system, it is also possible to install the development version of networkx .
Before installing the development version, you may need to uninstall the standard version of networkx using pip :
$ pip uninstall networkx
$ git clone https://github.com/networkx/networkx.git $ cd networkx $ pip install -e .[default]
The pip install -e .[default] command allows you to follow the development branch as it changes by creating links in the right places and installing the command line scripts to the appropriate locations.
Then, if you want to update networkx at any time, in the same directory do:
$ git pull
Extra packages#
Some optional packages may require compiling C or C++ code. If you have difficulty installing these packages with pip , please consult the homepages of those packages.
The following extra packages provide additional functionality. See the files in the requirements/ directory for information about specific version requirements.
- PyGraphviz and pydot provide graph drawing and graph layout algorithms via GraphViz.
- lxml used for GraphML XML format.
To install networkx and extra packages, do:
$ pip install networkx[default,extra]
To explicitly install all optional packages, do:
$ pip install pygraphviz pydot lxml
Or, install any optional package (e.g., pygraphviz ) individually:
$ pip install pygraphviz
Testing#
NetworkX uses the Python pytest testing package. You can learn more about pytest on their homepage.
Test a source distribution#
You can test the complete package from the unpacked source directory with:
pytest networkx
Test an installed package#
From a shell command prompt you can test the installed package with:
pytest --pyargs networkx
Installation
Prophet has two implementations: R and Python.
Installation in R
Prophet is a CRAN package so you can use install.packages .
# R install.packages('prophet')
After installation, you can get started!
Experimental backend — cmdstanr
You can also choose an experimental alternative stan backend called cmdstanr . Once you’ve installed prophet , follow these instructions to use cmdstanr instead of rstan as the backend:
1 2 3 4 5 6 7 8 9 10 11# R # We recommend running this is a fresh R session or restarting your current session install.packages(c("cmdstanr", "posterior"), repos = c("https://mc-stan.org/r-packages/", getOption("repos"))) # If you haven't installed cmdstan before, run: cmdstanr::install_cmdstan() # Otherwise, you can point cmdstanr to your cmdstan path: cmdstanr::set_cmdstan_path(path = your existing cmdstan>) # Set the R_STAN_BACKEND environment variable Sys.setenv(R_STAN_BACKEND = "CMDSTANR")Windows
On Windows, R requires a compiler so you’ll need to follow the instructions provided by rstan . The key step is installing Rtools before attempting to install the package.
If you have custom Stan compiler settings, install from source rather than the CRAN binary.
Installation in Python
Prophet is on PyPI, so you can use pip to install it.
python -m pip install prophet
- From v0.6 onwards, Python 2 is no longer supported.
- As of v1.0, the package name on PyPI is “prophet”; prior to v1.0 it was “fbprophet”.
- As of v1.1, the minimum supported Python version is 3.7.
After installation, you can get started!
Anaconda
Prophet can also be installed through conda-forge.
conda install -c conda-forge prophet
