How to specify the Python version I want to install lxml in? - python

I am new to Linux. On my Oracle Virtual Machine, I have several versions of Python installed.
Now I would like to install the lxml library in my Python 3.7, but I don't know how to specify the terminal to do so. The command pip install lxml that was recommanded to me returns : Requirement already satisfied : lxml in <my path to Python 3.8>
What I understand is that by default, it installs lxml in Python 3.8. How can I change that into Python 3.7 please ?

How can I change that into Python 3.7 please ?
According to python docs regarding working with multiple versions of python installed in parallel you might
On Linux, Mac OS X, and other POSIX systems, use the versioned Python
commands in combination with the -m switch to run the appropriate copy
of pip
so in your case
python3.7 -m pip install lxml

You must know how to start the Python3.7 version. If you start it with full_path_to_python37, then you should use the following to install lxml in it:
full_path_to_python37 -m pip install lxml

Related

pip installs python library under wrong version of python

On the Linux Mint O.S. I used pip to install the CherryPy module. However it installed it under python2.7 in :
/home/jacslim/.local/lib/python2.7/site-packages/cherrypy
rather than under Python 3.6 which I found in /usr/bin/python3.6,
I tried again in the Pyton3.6 directory but the same thing happened.
Is there anyway I can direct pip to use the latest version of the Python interpreter?
Use pip3 install to install for python 3
pip is usually in the same bin directory as your python, so make sure you just specify the correct bin housing your pip installation.
I use anaconda and my Python 2.7 is installed in:
/anaconda2/bin/
To get pip installs specific to that Python, I therefore use:
/anaconda2/bin/pip [name_of_thing_to_install]

Installing Python Libraries When Multiple Versions of Python Exist

When I run python -V from terminal, I see that Python 2.7.10 is installed. I want to keep this as the "global" version as OSX utilizes it.
When I run Idle, I see that Python 3.6.0 is running. How do I install libraries to this version of Python?
For example, if I run pip install bs4, the library is installed here beautifulsoup4 in /Library/Python/2.7/site-packages/beautifulsoup4-4.5.3-py2.7.egg - which is obviously Python 2.7.
So when I run my script from Idle, I get the following error:
ModuleNotFoundError: No module named 'bs4'
You want to use virtualenv. It sounds like you have two versions of Python installed and you need to focus on one while being able to manage the packages in each. Virtualenv will do this for you.
First install virtualenv (https://virtualenv.pypa.io/en/stable/),
Second run it specifying the version of python you want as so: `virtualenv -p /usr/bin/python2.6
Third you can use pip to install packages directly into this environment. This increases the amount of disk space you need, but will allow you greater control over your code.
When you have two versions of python, you will need to specify which version of python you would like to run. You can do this with the activate command. For example:
activate python3
Once you have activated the python 3 environment, you can then run pip:
pip3 install bs4
which will install the beautiful soup library in your python 3 environment.
Another answer was found here: https://stackoverflow.com/a/4910393/1580659
pipVERSIONNUMBER install will install the library to the correct version of Python.
$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage

Which version of Pip to use with my Python installs?

Being new to Python, I'd love to clear up a few points that I couldn't get from reading various articles and tutorials.
After using Homebrew to install Python3, I noticed that it had installed both Python3 and Python3.4. I was also a little surprised that there are now three versions of pip on my machine too; pip, pip3 and pip3.4.
I created a new virtualenv and told it to use Python3, using the following command:
virtualenv -p /usr/local/bin/python3 mysite
I was also surprised that the version of Python that it installed in my VM was 3.4.
Is it safe to have these multiple version of Python and Pip hanging around on my machine?
Am I right to assume that I should take extra care to use the matching version of pip with Python, for example, pip3.4 with Python3.4?
Yes, it is safe. Python uses this naming like python3.4, python3.5 etc to differentiate between releases. python3 is a symbolic link to the current python3.x version. Pip follows the same convention.
If you're using python3.4 explicitly, you should be using pip3.4 specifically as well. Otherwise, just use python3 and pip3. For Python 2, you can simply use python (which, unless you installed the Homebrew version as well), will be the system Python), and ditto for pip. python2.7 and pip2.7 may also work.
In general, to find out which Python version goes with which pip you're using, try:
pip --version
and you'll see the Python included in the result.
No need to worried about if you have multiple version of Python and Pip installed. just check your version by writing in terminal :
$ brew info python
or to check the version of pip write in terminal :
$ brew info pip
and make sure you have updated your both pip and python version (write in terminal $ brew upgrade pip/python)
and other way to install python is go to https://www.python.org/downloads/ and choose as your requirement, there is two version available 2.7.9 & 3.4.3 ,
after installing python write in terminal $ python -V to check its version :) Hope it will help :)

Python: pip installing requests for older version: 2.7

I'm trying to interface with an API using a python program that only works in 2.7 and not in 3.4 which is also installed on my machine. However, one of my program's dependencies is the requests module. I have requests available in my 3.4 environment, but in 2.7 import requests results in:
import error: no such module named requests
Many Stack Overflow Q&A's have reccomended installing requests for 2.7 using: pip2.7 install requests, but apparently I don't have pip2.7 because that results in:
'pip2.7' is not recognized as an internal or external command
Question: How can I get pip2.7 instead of my default pip? Is it a seperate version of pip or do I just need to tell my current version I'm trying to install for version 2.7 not 2.4?
Note: The suggested solution to use easy_install-2.7 -U pip to install pip2.7 doesn't run on my Windows7 maching, the command propmt prints : easy_instal-2.7 is not recognized as an internal or external command
By default 3.4 won't create the plain pip command but it can be enabled with an option which is presumably what has been done in your case. Since there are other names for the Python 3 pip you can safely overwrite it by installing the 2.7 pip on top of it with easy_install.
Since this is Windows, your Python binaries are kept in isolated directories so you should just ensure that the 2.7 directory is first in the path variable. Look in the <python root 2.7>\Scripts directory to see if you have an easy_install already. If not you need to install setuptools.

Python can't get requests installed on Ubuntu for Python 2.7

All I want to do is run a Python script that requires Python 2.7 & Requests on my Ubuntu 10.04 EC2 box.
I installed Python 2.7, no problem. "python" by itself still points to python 2.6, which is very annoying, b/c I'm not sure how ubuntu will freak if I change the symlink /usr/bin/python to point to 2.7.
I followed the (carefully buried) install instructions for pip (at http://www.pip-installer.org/en/latest/index.html, and which are WAY too hard to find if they aren't the ABSOLUTE FIRST command on the "install pip" page)
So, the real problem here is that pip install requests completes successfully, but only installs for python 2.6, not 2.7. The pip usage instructions say nothing about how to install a package for a specific version of python.
How do I do this?
I just want to run my python script that requires 2.7 + requests.
First install pip for your 2.7 distribution using easy_install (easy_install should definitely be included with your 2.7 distribution):
easy_install-2.7 -U pip
Then install what you need:
pip-2.7 install requests
Then you can run code with python2.7 instead of python.
Yeah it would be a bad idea to change the link pointing to which python version. Instead, can you change the shebang to say #!/usr/bin/env python2.7 instead of #!/usr/bin/env python ?
Though python2.7 /path/to/pip install requests might work; you should install pip for python2.7 separately instead.
If you don't use virtualenv then invoke pip as pip-2.7 (the command is available if you install pip for python2.7).
Follow installation instructions which is the first item in the table of contents. Substitute python with python2.7 in the instructions.

Categories

Resources