Cannot install python package properly in a new ubuntu laptop - python

I moved from Windows to Linux and I try to set up all my libraries in Python as I had in Windows. Since, I am new on Linux, I don't know a lot.
I follow this procedure:
sudo apt-get install python3-pip
To install the pip
sudo pip3 install bottle
To install the Bottle library. The output message didn't has any error. It said that the install completed. Then I tried to run a python file I have which import this library, but I have the error
ImportError: No module named bottle
I tried also to run Python from terminal and check to import the package there, but I have the same error.
Edit: For Python version
readlink -f $(which python) | xargs -I % sh -c 'echo -n "%: "; % -V'
/usr/bin/python2.7: Python 2.7.6

You have installed a package for python3 but are using it in a python2 shell, python by default refers to python2 on ubuntu 14.04 . You need to use python3 when referring to the python3 interpreter and to start a python3 shell

Related

Python and pip installation on Mac don't show version?

On Mac OS.
Downloaded the Python from their website.
Python -V return Python 2.7.16, and
python3 -V return Python 3.9.4
Installed pip with : python3 get-pip.py, got Successfully installed pip-21.0.1
But when I run pip -V
I get File "/usr/local/bin/pip", line 1.... SyntaxError: invalid syntax
After reading here a lot, i could not understand (in simple words for dumbs) :
How could you "alias" or update python to show/run in version 3+ ?
Why I can't get the pip version if it's installed ?
Use pip as a module instead
% python3 -m pip --version
pip 21.0.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
Anyone who's interested , what i had to do is to
CD the project on terminal
run python3 -m venv env (this create virtual environment of python3 inside project)
run source env/bin/activate activate it.
now pip --version or python --version will return the right results.
From my basic knowledge i understand that the mac is using python2 which we don't want to interrupt, so we install python3 and create a 'virtual environment' for it inside our project folder, once its in, we can install all other things.
to deactivate (stop the virtual env) we run deactivate

Why doesn't "python3 [command]" do anything?

I am trying to use pip to install discord.py. When I simply type pip install discord.py, it defaults to 2.7 and complains that it needs 3.4+. When I say python3 -m pip [command], nothing is printed to stdout, and as far as I can tell nothing happens at all. What am I doing wrong?
EDIT: The problem seems to extend to all python3 commands - "python3 --version" doesn't do anything either.
Resolution: I installed Python 3.8.0 earlier today. I restarted my computer, and now the default version has been changed to 3.8.0 and everything's working just fine.
check python version
python3 --version
if it is 3.5+ , good , then do in terminal
python3 go to python prompt
import pip check if pip is there or not if not then install it
in ubuntu run command sudo apt install python3-pip
verify again it is installed or not
then do python3 -m pip install discord.py
try using python3 -m pip3 [command] instead. pip3 is used to install python 3 packages.
I highly recommend using a virtual environment. So if you perform virtualenv -p python3 you will have a python3 environment. Then source bin/activate then you should be able to successfully run pip 3 commands simply by using pip install discord.py. Hope this helps!

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

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/

IPython Notebook in a virtualenv, using Python 3.3

I have my Ubuntu 12.04 system set up so that I can create a virtualenv with either Python 2.7 or Python 3.3, and run IPython Notebook. The problem is, I don't know exactly what I did to my system to make this possible. I am trying to help someone else get their system set up the same way, and I'm not sure what packages I am missing.
On my system I can run the following commands to get IPython Notebook running in a virtualenv:
~$ mkdir test_ipython3.3
~$ cd test_ipython3.3
~/test_ipython3.3$ virtualenv -p python3.3 venv
~/test_ipython3.3$ source venv/bin/activate
(venv)~/test_ipython3.3$ pip install ipython[all]==1.1.0
I can do the same set of commands with virtualenv -p python2.7 venv, and have an almost identical environment except it runs Python 2.7.
I am trying to get a 12.04 installation on virtualbox set up so that I can run these commands successfully as well, but I keep failing. After building a clean Ubuntu 12.04 machine in virtualbox, I do the following:
# Update machine:
sudo apt-get update
sudo apt-get dist-upgrade
# Install Python 3.3:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.3
# Install virtualenv
sudo apt-get install python-pip
sudo pip install pip --upgrade
sudo pip install virtualenv
# Install necessary packages:
sudo apt-get install python-dev python3.3-dev libzmq-dev
# Build a venv, using Python 2.7, which works:
~$ mkdir test_ipython2.7
~$ cd test_ipython2.7
~/test_ipython2.7$ virtualenv -p python2.7 venv
~/test_ipython2.7$ source venv/bin/activate
(venv)~/test_ipython2.7$ pip install ipython[all]==1.1.0
(venv)~/test_ipython2.7$ ipython notebook
# Works, opening an ipynb that runs Python 3.3
# Build a venv, using Python 3.3, which fails:
~$ mkdir test_ipython3.3
~$ cd test_ipython3.3
~/test_ipython3.3$ virtualenv -p python3.3 venv
~/test_ipython3.3$ source venv/bin/activate
(venv)~/test_ipython3.3$ pip install ipython[all]==1.1.0
(venv)~/test_ipython3.3$ ipython notebook
# Fails, says that ipython is not installed, despite having reported otherwise
After trying to install ipython in the 3.3 virtualenv, I get a message that ipython and a number of supporting packages have been installed successfully. But when I try to run ipython or ipython notebook, I get a message that ipython is not installed. Watching the install process, and scrolling back through the output, I can't find any obvious failures. I even installed zmq from source, so I have zmq 4.0.3 installed, which ipython is finding during its installation.
Can anyone spot where I am going wrong?
IPython 1.x creates scripts with a '3' suffix when installed with Python 3, to avoid conflict with IPython installed with Python 2, so the command you want is:
ipython3 notebook
In current development IPython (will be 2.0), this behavior is changed somewhat, where IPython installs both the non-suffix and the suffix entry points (ipython and ipython3 on Python 3, ipython and ipython2 on Python 2), following the pattern established by other packages, such as nose.
I'm still quite curious about the best way to install ipython when you want access to a 2.7 interpreter sometimes, and a 3.3 interpreter other times.
There are two ways to deal with this:
The first is to create an ipython script somewhere very high priority in your PATH (I use ~/bin),
with the contents:
#!/usr/bin/env python
import IPython
IPython.start_ipython()
This will use the current python on your PATH, no matter what, so when you activate a Python 3 env, ipython will use that, etc.
The second is to just use:
python -m IPython
or
python3 -m IPython
which is the same as typing ipython, but you are specifying the interpreter to use explicitly, so there can be no doubt about what Python is in use.
These problems seem to be solved at: http://ihrke.github.io/jupyter.html

Categories

Resources