Multiple Python leads to installation of boto at wrong location - python

I am on Centos7. I have multiple Python versions (Totally newbie in python).
One at my root inside folder name Python-2.6.6 which i installed following these steps :
wget https://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
tar -zxvf Python-2.6.6.tgz
cd Python-2.6.6
sudo yum install gcc gcc-c++
make
make install
However there is also a Python folder at /usr/lib/python2.7/site-packages
Which i have no idea how got created .
Now i installed boto using
sudo yum -y install python-pip
sudo pip install boto
installation ended with comments
Installing collected packages: boto
Successfully installed boto-2.47.0
Now when i do python --version , I do get Python 2.6.6 which is expected
which python : /usr/local/bin/python
but when i do import boto
i get
import boto
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named boto
WHY YOU NO IMPORT?Please help

CentOs 7 is delivered with python 2.7 by default.
You installed boto with pip wich is "bind" to python 2.7, that's why you can't import boto using python 2.6. pip is bind to python2.7, cause it's the default version in CentOs 7.
You should use virtualenv. It allows you to create a python environnement with a specific python version and install the modules needed.
Example:
virtualenv -p /usr/bin/python2.7 /home/user/my_project
cd ./my_project
source bin/active
Now you're in a python virtualenv. The first command points to python2.7, but you can make it point to any python version installed (compiled, from repos etc.). Once you sourced the active file you can install modules using pip
Edit
To run a script using your virtualenv (without sourcing ./bin/active):
/home/user/my_project/bin/python /path/my_script.py
If you use this command :
source bin/activate
Then you can use pip to add a lib to the virtualenv.
Edit 2
So, you're on Centos 7, wich is provided with python 2.7. You want to use python 2.6 with a specific script.
Install python 2.6 (let's say in /usr/bin/python2.6)
Create a virtuanlenv with python 2.6 :
virtualenv -p /usr/bin/python2.6 my_venv
Enter the virtualenv
cd my_env
source bin/activate
Check the python version (should return python 2.6.x)
python
Install a module with pip :
pip install boto
boto will be installed with python 2.6, so you will be able to use your script.
If for some reason pip is not installed :
yum install python-pip

Related

How to install pip associated to different versions of Python

Currently, I am running two versions of python on Mac. The native one (2.7.10) (/usr/bin/python), and another one, which has been downloaded via home-brew (2.7.14).
I want to download two versions of pip and download packages depending on the python version I want to use.
Is this possible?
Start by checking your available Python interpreters on your command line:
[root#server ~]# ls /usr/bin/ | grep python
python2 -> python2.6
python2.6
python3 -> python3.4
python3.4
Then download and run this file using each interpreter
[root#server ~]# python2.6 get-pip.py
[root#server ~]# python3.4 get-pip.py
Then once both Python interpreters have thepip module installed, you can install packages to your specific Python interpreters using the following commands:
[root#server ~]# python2.6 -m pip install <module>
[root#server ~]# python3.4 -m pip install <module>
It's worth mentioning (for Windows Users), once you have multiple versions of Python installed, you can easily manage packages for each specific version by calling pip<major>.<minor> from a cmd window.
for example, I have Python 2.7, 3.6 and 3.7 currently installed, and I can manage my packages for each installation using pip2.7, pip3.6 and pip3.7 respectively ...
On Windows 10, $ pip3.7 install <module> works for me - haven't tested it with venv instances yet though

How to install pip for a specific python version

I have my deployment system running CentOS 6.
It has by default python 2.6.6 installed. So, "which python" gives me /usr/bin/python (which is 2.6.6)
I later installed python3.5, which is invoked as python3 ("which python3" gives me /usr/local/bin/python3)
Using pip, I need to install a few packages that are specific to python3. So I did pip install using:-
"sudo yum install python-pip"
So "which pip" is /usr/bin/pip.
Now whenever I do any "pip install", it just installs it for 2.6.6. :-(
It is clear that pip installation got tied to python 2.6.6 and invoking pip later, only installs packages for 2.6.6.
How can I get around this issue?
If pip isn’t already installed, then first try to bootstrap it from the standard library:
$ python3.5 -m ensurepip --default-pip
If that still doesn’t allow you to run pip:
Securely Download get-pip.py.
Run sudo python3.5 get-pip.py.
Now you can use pip3 to install packages for python3.5. For example, try:
$ sudo pip3 install ipython # isntall IPython for python3.5
Alternatively, as long as the corresponding pip has been installed, you can use pip for a specific Python version like this:
$ python3.5 -m pip install SomePackage # specifically Python 3.5
References:
Ensure you can run pip from the command line
work with multiple versions of Python installed in parallel?
I have python 3.6 and 3.8 on my Ubuntu 18.04 WSL machine. Running
sudo apt-get install python3-pip
pip3 install my_package_name
kept installing packages into Python 3.6 dist directories. The only way that I could install packages for Python 3.8 was:
python3.8 -m pip install my_package_name
That installed appropriate package into the Python 3.8 dist package directory so that when I ran my code with python3.8, the required package was available.
Example of how to install pip for a specific python version
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
/opt/local/bin/python2.7 get-pip.py
Script is from official doc: https://pip.pypa.io/en/stable/installing/
On Ubuntu 18.04.1 LTS I wanted to install pip for my second python version (python3) and the following command did the trick for me:
$ sudo apt install python3-pip

Ubuntu Python "No module named paramiko"

So I'm trying to use Paramiko on Ubuntu with Python 2.7, but import paramiko causes this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named paramiko
The other questions on this site don't help me since I'm new to Ubuntu.
Here are some important commands that I ran to check stuff:
sudo pip install paramiko
pip install paramiko
sudo apt-get install python-paramiko
Paramiko did "install". These are the only commands I used to "install" paramiko. I'm new to Ubuntu, so if I need to run more commands, lay them on me.
which python
/usr/local/bin/python
python -c "from pprint import pprint; import sys; pprint(sys.path);"
['',
'/usr/local/lib/python27.zip',
'/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk',
'/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']
In the python interpreter, I ran help("modules") and Paramiko is not in the list.
two paramiko folders are located in usr/local/lib/python2.7/dist-packages.
Short version: You're mixing Ubuntu's packaged version of Python (/usr/bin/python) and a locally built and installed version (/usr/local/bin/python).
Long version:
You used apt-get install python-paramiko to install Ubuntu's official Paramiko package to /usr/lib/python2.7/dist-packages.
You used (I assume) Ubuntu's version of pip, which installs to /usr/local/lib/python2.7/dist-packages. (See here.)
You used a locally built version of Python, and because it's locally built, it uses /usr/local/lib/python2.7 instead of /usr/lib/python2.7, and because it doesn't have Debian/Ubuntu customizations, it doesn't check use dist-packages.
Solution: You should be able to add /usr/local/lib/python2.7/dist-packages to your /usr/local/bin/python's sys.path, but since you're using Ubuntu, it's easiest to let Ubuntu do the work for you:
Use /usr/bin/python instead of a local version.
Use Ubuntu's packages wherever possible (i.e., use apt-get instead of pip).
Use virtualenv for the rest (to keep a clean separation between Ubuntu-packaged and personally installed modules).
I'd go so far as to uninstall the local version of Python and delete /usr/local/lib/python2.7, to ensure that no further mismatches occur. If you don't want to be that drastic, then you can edit your $PATH to put /usr/bin before /usr/local/bin to run the system version of Python by default.
Try downloading the zip file from https://github.com/paramiko/paramiko and running this command in the unzipped directory :
python setup.py install
There are two others methodes for add modules in python :
The first :
Download the package.
Create directory and paste the package in it.
Tap in the terminal :
export PYTHONPATH=$PYTHONPATH:path_of_package
The second :
open python interpreter:
import sys
sys.path.insert(0, "path_of_package")
Try installing only through commands.
Download paramiko package from git using this command: git clone https://github.com/paramiko/paramiko.git
Go to unzipped directory and run export PYTHONPATH=$PYTHONPATH:<path_to_paramiko>
If you find libffi package not found then run this command: sudo apt-get install libffi6 libffi-dev and If you haven't properly installed the header files and static libraries for python dev then run this command: sudo apt-get install python-dev
Enjoy :)
Also, mind the version of python, if the error was reported by python3, then install python3's paramiko.
If you're using Python 3, type the below command
$ sudo -H pip3 install paramiko --ignore-installed
try type pi then tap, this give you this
:$ pi
pic piconv pidstat pinentry-curses ping6
pip3 pivot_root
pic2graph pidof pinentry ping pinky
pip3.6
then you type in whereis pip3
$ whereis pip3
pip3: /usr/local/bin/pip3.6 /usr/local/bin/pip3
xg#xx-ppmaster:/xg/scripts/pyth
$ sudo /usr/local/bin/pip3 install paramiko
This should let you install paramiko
more on python installation
https://danieleriksson.net/2017/02/08/how-to-install-latest-python-on-centos/

How to install django for python 3.3

I had python 2.6.1 because it was old I decide to install python 3.3.2 but, when I type "python" in my mac it prints it is version 2.6.1 and when I type python3 it shows that this is 3.3.2. I installed django 1.6 but when I check, understand that it is installed for old version of python (python 2.6.1). I want to instal it for my python 3.3.2 what should I do? any way to uninstall python 2.6.1 and when I enter python in terminal it's version be 3.3.2? I have mac os 10.6.8
You could use pip to manage the package for you. If pip is not installed.
use
sudo easy_install pip
to install it. Then
pip3 install django
would install django for your python3.
Use python3 to call python version 3 on the command line.
For projects you can use virtual environments:
$ python # this will be version 2
$ python3 -m venv myenv
$ source myenv/bin/activate
$ python # this will be version 3
where myenv will be the folder that hosts the libraries and binaries for that virtual environment. It will automcatically use the python version that was used to initialize this venv - in this case python3. This has the effect that once you activate the venv you can use python there and it will be version 3.
to setup django in pyton3
sudo apt-get install python3-pip
sudo pip3 install virtualenv
virtualenv -p /usr/bin/python3.X venv
source venv/bin/activate
congrats you have setup python3 django and now have many packages to work with
Note: X stands for the version of python
To install django for python3, you need to use pip3 instead of pip.
python defaults to python2.
pip defaults to pip for python2.
So, when you install pip using whatever package manager you have, you are essentially installing pip for python2.
To remove Python2: $sudo apt remove python
To install pip for python3:
$sudo apt install python3-pip
To install pip for python2:
$sudo apt install python-pip
Note: I am using apt package manager. You should use the package manager for your OS.

Installing pip with correct python version

I am on shared hosting and I need to install pip with the correct python version, 2.7. To install pip, I did:
$ easy_install pip
However, after it was installed I get the following:
[dave#web1 lib]$ pip --version
pip 1.0.2 from /home/premiere/dave/financials/lib/pip-1.0.2-py2.7.egg (python 2.4)
How would I re-install pip to work on the python2.7 version, which is also installed on the machine?
[premiered#web1 ~]$ python --version
Python 2.6.6
Which is strange, since it is installing to python2.4.
You may want to create a virtualenv using -p /path/to/python-2.7.binary param, and then activate it. Then all stuff you installed using pip would be correctly into your virtualenv.
If multiple versions of python are installed on the system, then you should invoke the version you want when installing. i.e.
$ python27 easy_install pip
This creates a pip file in your path that contains the specified version of python in the hashBang line.

Categories

Resources