简体   繁体   中英

Using Pip and Importing Packages in Python 3 on Ubuntu

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM