Using Pip and Importing Packages in Python 3 on Ubuntu - python

I'm on Lubuntu (a minimal build of Ubuntu). I installed Python 3.6.1 with:
sudo apt-get install python3.6
I want to use Twilio, so I tried this:
pip install twilio
It said pip wasn't recognized, so I ran this, followed by the above again:
sudo apt install python-pip
I fired up Python 3.6 and tried importing it, but that didn't work out:
>>> from twilio.rest import Client
ModuleNotFoundError: No module named 'twilio'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
I'm new to python3 (which I want to use for the secrets module), Ubuntu, and twilio, so I'm not really sure what's going on here. I'd think if it was as simple as a module not being found, the stack trace would be much shorter... I'm not sure if the stack trace is so long because maybe Python 3 produces longer ones than 2 did, or Ubuntu is trying to do something weird because both Python 2 and 3 are installed (and perhaps two versions of 3 at that), or if maybe this is the work of twilio?

Try the following to download pip:
wget https://bootstrap.pypa.io/get-pip.py
Then install pip by running:
sudo python3 get-pip.py
Then you can install twilio with pip
sudo pip3 install twilio

Related

ROS rqt_graph does not launch anymore (ImportError DEFAULT_MASTER_PORT)

Recently I installed the offline simulator from Universal Robots, and the install.sh turned out to remove my entire ROS install. Fine. I re-installed it following the official guide, and now rqt_graph does not work:
usr#legion:~/Documents/catkin_ws$ rqt_graph
Traceback (most recent call last):
File "/opt/ros/melodic/bin/rqt_graph", line 5, in <module>
from rqt_gui.main import Main
File "/opt/ros/melodic/lib/python2.7/dist-packages/rqt_gui/main.py", line 41, in <module>
import rospy
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/__init__.py", line 49, in <module>
from .client import spin, myargv, init_node, \
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/client.py", line 60, in <module>
import rospy.impl.init
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/impl/init.py", line 58, in <module>
from rosgraph.rosenv import DEFAULT_MASTER_PORT # default port for master's to bind to
ImportError: cannot import name DEFAULT_MASTER_PORT
(roscore is running in another terminal)
I tried sudo apt install ros-melodic-rqt and sudo apt-get install python-rosgraph, but the error persists.
I dug and found out that this specific variable had been added to that file in the melodic distribution, so there may be a version conflict but I don't know how to check that.
How to proceed?
I finally did sudo apt-get update and sudo apt-get upgrade and some ros packages have been updated, it works now. This may be useful to some :)

trying to install pyperclip in python2.7

everytime i run this i face this problem
> sudo pip install pyperclip
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
File "/home/ot/.local/lib/python2.7/site-packages/pip/__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/ot/.local/lib/python2.7/site-packages/pip/utils/__init__.py", line 22, in <module>
from pip.compat import console_to_str, expanduser, stdlib_pkgs
ImportError: No module named compat
ps: im using python 2.7 and this has been happening to me while trying to download other few packages as well
I'm on ubuntu 16.04
Thank you
problem solved i used these 2 lines :
sudo apt-get update
sudo apt-get install python-pyperclip

python3 pip broken. missing distutils

I have been trying to get pip with python3 on WSL ubuntu 16.04 and have had no success. I have been running sudo apt install --reinstall python3-pip, but still have issues getting pip to work properly.
$ pip3
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 14, in
<module>
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in
<module>
from pip.locations import (
File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in
<module>
from distutils import sysconfig
ImportError: No module named 'distutils'
Similar with sudo
$ sudo pip3
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 14, in
<module>
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in
<module>
from pip.locations import (
File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in <module>
from distutils import sysconfig
ImportError: No module named 'distutils'
Also I noticed that I seem to have two versions of python3 installed:
$ ls /usr/lib | grep python
python2.7
python3
python3.5
According to Python 3 documentation, distutils apparently is not deprecated, BUT, my install of 2.7 has disutils, but 3.6 does not.
When I read:
https://docs.python.org/3/installing/
It seemed to say that distutils was being deprecated, but it was not worded clearly if they were talking about distutils or something else.
If anyone knows the definitive answer, please let us know.
So after a lot of pain, I finally gave in. I had made things worse and corrupted my entire python3 installation. I had corrupted too many files trying to fix everything. I ended up uninstalling WSL/ubuntu and reinstalling clean. I made of backup a few things first.
Unfortunately, this seems to be the best option if you have really messed this up, like I did. Being more careful now, python3 is working just fine, with pip. Make sure you follow official docs when you install.

python3.5 pip ImportError: cannot import name 'HTTPSHandler'

everybody.
Firstly,my OS is RHEL7.2,and I use python3.5.
I want to use pip to do something I want.And then ,after I install pip3 successfully,I want to use pip to install something,but it shows me ImportError: cannot import name 'HTTPSHandler'.And I follow the solution on website to yum install openssl-devel,but it shows the error :
Transaction check error:
file /usr/bin/sclient from install of krb5-devel-1.13.2-10.el7.x86_64 conflicts with file from package krb5-server-1.13.2-10.el7.x86_64
file /usr/sbin/sserver from install of krb5-devel-1.13.2-10.el7.x86_64 conflicts with file from package krb5-server-1.13.2-10.el7.x86_64
I can't solve it independently.I hope you can help me.Thanks.
PS:the whole error message is:
[fen#localhost Downloads]$ pip pip-8.0.2-py2.py3-none-any.whl install
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
load_entry_point('pip==8.1.1', 'console_scripts', 'pip')()
File "/usr/local/python3.5/lib/python3.5/site-packages/setuptools-20.3.1-py3.5.egg/pkg_resources/__init__.py", line 549, in load_entry_point
File "/usr/local/python3.5/lib/python3.5/site-packages/setuptools-20.3.1-py3.5.egg/pkg_resources/__init__.py", line 2542, in load_entry_point
File "/usr/local/python3.5/lib/python3.5/site-packages/setuptools-20.3.1-py3.5.egg/pkg_resources/__init__.py", line 2202, in load
File "/usr/local/python3.5/lib/python3.5/site-packages/setuptools-20.3.1-py3.5.egg/pkg_resources/__init__.py", line 2208, in resolve
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/wheel.py", line 39, in <module>
from pip._vendor.distlib.scripts import ScriptMaker
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/_vendor/distlib/scripts.py", line 14, in <module>
from .compat import sysconfig, detect_encoding, ZipFile
File "/usr/local/python3.5/lib/python3.5/site-packages/pip-8.1.1-py3.5.egg/pip/_vendor/distlib/compat.py", line 66, in <module>
from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
ImportError: cannot import name 'HTTPSHandler'
I solved my problem.
I have so many repositories and some data in one repository conflict with another. So I follow the first suggestion: I reinstall krb5-server, and then I yum install openssl-devel and it works well.
After I solve the first problem, I use pip unsuccessfully and I follow the second suggestion: I recompile the python3.5 and the problem is solved.
First check wheather install openssl-develop
sudo apt-get install libssl-dev
or
yum install openssl-dev -y
Try another way to reinstall pip3 ,take Ubuntu for example
sudo apt-get install python3-setuptools
sudo easy_install3 pip
use setuptools to install pip may can solve the problem of dependency.
Try it on RHEL
sudo yum install -y python35-setuptools
sudo easy_install-3.5 pip

pip Not Working Python 2.7

I am having a problem with pip just now, when I try to install something like pip install readline then I get an error:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 549, in load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2709, in load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2369, in load
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2375, in resolve
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 25, in <module>
from requests.compat import IncompleteRead
ImportError: cannot import name IncompleteRead
So I ran cat /usr/local/bin/pip which tells me pip==1.5.6. I tried to find a solution online regarding this and one solution told to cd /usr/local/lib/python2.7/site-packages && ls but for me I see that folder is also empty.
If upgrading pip doesn't work, you should try uninstalling it and reinstalling it. The error you're encountering is likely due to a mismatch in versions between pip and requests. First, I would remove pip and reinstall it from the source with python like this:
sudo apt-get remove python-pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
From the Ubuntu launchpad site
Just check If You have installed python-setuptools rpm, If this is installed You can use easy_install pip on Redhat Based System.
I would comment this but due to low reputation I can't. Did you try upgrading pip?
pip install --upgrade pip
And then try to do that again.
If you are using Debian flavor OS (like Ubuntu) try this
apt-get remove python-pip
Then try to install the latest version by easy_install
easy_install pip

Categories