Misam Mehmannavaz
Misam Mehmannavaz

Reputation: 156

How to install older version of python when we have installed a newer version

I'm a novice python programmer and I have installed python 3.7 and 2.7. I tried to install python 3.5.7 with 'python setup.py install' command in cmd(for use dlib library) but it didn't install and this is the error:

Traceback (most recent call last):File "setup.py", line 25, in <module>sysconfig.get_config_vars()['CFLAGS'] = cflags + ' ' + py_cflags_nodist

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

I tried to install python 3.4.9 but same error occured.

Upvotes: 2

Views: 5850

Answers (2)

Alok
Alok

Reputation: 10544

You can always install another version of python side by side.

https://www.python.org/ftp/python/

See this link for downloading your desired python version executable or source code.

on windows you need to for .exe or .msi file
on Linux you need to for .tgz file (we need to compile to install)
on MacOS you need to for .pkg file

Upvotes: 0

therj
therj

Reputation: 151

Popular Linux distros, like Ubuntu, come with both python2 and python3. You can set one as default python and access other as python3 (or python2).

On Windows, the executable is just python (NOT python2). The newer python will overwrite the older executable (not the actual installation files, but the environment path).

Way 1: Instead of running python filename.py, give path to python binary. Like C:/python27/bin/python filename.py, make sure the path to python is correct. This will use python from particular directory. This can be cumbersome, I don't recommend this.

Way 2: Make an alias python2 referring to /path/to/python2, run as python2 filename.py. Don't forget to add this alias to environment variables.

Way 3: Set up a virtual environment. The default venv [now] included in python3, does not support creating virtual environment with a different python version. Use virtualenv instead.

virtualenv --python=C:/python27/bin/python2.7 /path/to/new/virtualenv/
/path/to/new/virtualenv/Scripts/activate.bat

Virtualenv documentation: https://pypi.org/project/virtualenv/

Upvotes: 1

Related Questions