How to install mesa (python package) for use in python 3

4.7k Views Asked by At

I have installed mesa via:

$ pip install mesa

but it is automatically installing it into

/Users/MyName/Documents/User/lib/python2.7/site-packages/mesa/~

which means that when I try to run it with a Python 3 kernel, it can't find the module and I receive the error

ModuleNotFoundError: No module named 'mesa'

Could someone help me out? I'm assuming the problem is that it is automatically installed into the python 2.7 directory - how can i change this?

Thanks

2

There are 2 best solutions below

1
On BEST ANSWER

To install packages for Python3 while exists Python2,

try this

python3 -m pip install xxx

or this

sudo apt install pip3 
pip3 install xxx 
0
On

You should use pip3 instead of pip:

pip3 install mesa

If you don't have pip3 install it using:

sudo apt-get update
sudo apt-get -y install python3-pip

If it doesn't work you can do it manually using curl:

curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py

You can also execute it straight from python3:

python3 -m pip install mesa

It is always a good practice to set pip command to be equivalent to your python command. i.e, if python points to python3, you better change pip to point to pip3. Add alias pip='pip3' to your ~/.bash_profile file.