Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install modules in Python 2.7 instead of Python 3.6?

I have two versions of Python in my laptop. Python 2.7 and Python 3.6. If install a module this is installed only in Python 3.6.

I would like to install modules in Python 2.7 through pip but I don't know how to do it.

I want to install right now GDAL and Fiona for Python 2.7 in Ubuntu 17.04.

like image 625
José Carlos Avatar asked Oct 28 '25 14:10

José Carlos


2 Answers

If Python 2.7 is well installed on your system, you should have python2 and/or python2.7 commands and you could run the following:

python2.7 -m pip install <your-packages>

To make sure you are running the correct python version, you can use python2.7 --version

like image 192
gogaz Avatar answered Oct 31 '25 02:10

gogaz


Better use virtual environment for this. Follow this link https://realpython.com/blog/python/python-virtual-environments-a-primer/

You can set python version to use in virtual env using

virtualenv -p path/to/python2.7 env_name

Activate this env using . env_name/bin/activate then,

Use pip install package_name to install libraries inside virtual environment

like image 31
paras_47 Avatar answered Oct 31 '25 02:10

paras_47



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!