簡體   English   中英

PIP 只會將軟件包安裝到 Python 2

[英]PIP will only install packages to Python 2

我有一台運行 Ubuntu 16.04 的計算機,我正在嘗試將其與 Python 一起使用。 我需要安裝 pyserial 包。 運行pip install pyserial沒有問題,但是當我嘗試在 python 3 (3.9.6) 中導入包時,我收到一個錯誤,提示沒有名為 serial 的模塊。 當我嘗試運行python3 -m pip install pyserial我收到一條錯誤消息/usr/local/bin/python3: No module named pip 我已經運行sudo apt-get install -y python3-pip沒有錯誤,但這並不能解決 pip 的問題。 與運行pip3 install pyserial而不僅僅是pip 我最近用 python 3.9.6 替換了 python 3.5.2,當我執行python3 -v我收到一條很長的錯誤消息(貼在下面),所以我認為這與它有關,但我不確定. 我不知道安裝是否搞砸了,還有一些事情需要清理,或者是否還有其他事情發生。

import _frozen_importlib # frozen
import _imp # builtin
import '_thread' # <class '_frozen_importlib.BuiltinImporter'>
import '_warnings' # <class '_frozen_importlib.BuiltinImporter'>
import '_weakref' # <class '_frozen_importlib.BuiltinImporter'>
import '_io' # <class '_frozen_importlib.BuiltinImporter'>
import 'marshal' # <class '_frozen_importlib.BuiltinImporter'>
import 'posix' # <class '_frozen_importlib.BuiltinImporter'>
import '_frozen_importlib_external' # <class '_frozen_importlib.FrozenImporter'>
# installing zipimport hook
import 'time' # <class '_frozen_importlib.BuiltinImporter'>
import 'zipimport' # <class '_frozen_importlib.FrozenImporter'>
# installed zipimport hook
# /usr/local/lib/python3.9/encodings/__pycache__/__init__.cpython-39.pyc matches /usr/local/lib/python3.9/encodings/__init__.py
# code object from '/usr/local/lib/python3.9/encodings/__pycache__/__init__.cpython-39.pyc'
# /usr/local/lib/python3.9/__pycache__/codecs.cpython-39.pyc matches /usr/local/lib/python3.9/codecs.py
# code object from '/usr/local/lib/python3.9/__pycache__/codecs.cpython-39.pyc'
import '_codecs' # <class '_frozen_importlib.BuiltinImporter'>
import 'codecs' # <_frozen_importlib_external.SourceFileLoader object at 0x7f41506b8700>
# /usr/local/lib/python3.9/encodings/__pycache__/aliases.cpython-39.pyc matches /usr/local/lib/python3.9/encodings/aliases.py
# code object from '/usr/local/lib/python3.9/encodings/__pycache__/aliases.cpython-39.pyc'
import 'encodings.aliases' # <_frozen_importlib_external.SourceFileLoader object at 0x7f4150653ca0>
import 'encodings' # <_frozen_importlib_external.SourceFileLoader object at 0x7f41506b8460>
# /usr/local/lib/python3.9/encodings/__pycache__/utf_8.cpython-39.pyc matches /usr/local/lib/python3.9/encodings/utf_8.py
# code object from '/usr/local/lib/python3.9/encodings/__pycache__/utf_8.cpython-39.pyc'
import 'encodings.utf_8' # <_frozen_importlib_external.SourceFileLoader object at 0x7f41506b8940>
import '_signal' # <class '_frozen_importlib.BuiltinImporter'>
# /usr/local/lib/python3.9/encodings/__pycache__/latin_1.cpython-39.pyc matches /usr/local/lib/python3.9/encodings/latin_1.py
# code object from '/usr/local/lib/python3.9/encodings/__pycache__/latin_1.cpython-39.pyc'
import 'encodings.latin_1' # <_frozen_importlib_external.SourceFileLoader object at 0x7f4150653d90>
# /usr/local/lib/python3.9/__pycache__/io.cpython-39.pyc matches /usr/local/lib/python3.9/io.py
# code object from '/usr/local/lib/python3.9/__pycache__/io.cpython-39.pyc'
# /usr/local/lib/python3.9/__pycache__/abc.cpython-39.pyc matches /usr/local/lib/python3.9/abc.py
# code object from '/usr/local/lib/python3.9/__pycache__/abc.cpython-39.pyc'
import '_abc' # <class '_frozen_importlib.BuiltinImporter'>
import 'abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7f415066b280>
import 'io' # <_frozen_importlib_external.SourceFileLoader object at 0x7f4150653f70>
# /usr/local/lib/python3.9/__pycache__/site.cpython-39.pyc matches /usr/local/lib/python3.9/site.py
# code object from '/usr/local/lib/python3.9/__pycache__/site.cpython-39.pyc'
# /usr/local/lib/python3.9/__pycache__/os.cpython-39.pyc matches /usr/local/lib/python3.9/os.py
# code object from '/usr/local/lib/python3.9/__pycache__/os.cpython-39.pyc'
# /usr/local/lib/python3.9/__pycache__/stat.cpython-39.pyc matches /usr/local/lib/python3.9/stat.py
# code object from '/usr/local/lib/python3.9/__pycache__/stat.cpython-39.pyc'
import '_stat' # <class '_frozen_importlib.BuiltinImporter'>
import 'stat' # <_frozen_importlib_external.SourceFileLoader object at 0x7f4150608af0>
# /usr/local/lib/python3.9/__pycache__/_collections_abc.cpython-39.pyc matches /usr/local/lib/python3.9/_collections_abc.py
# code object from '/usr/local/lib/python3.9/__pycache__/_collections_abc.cpython-39.pyc'
import '_collections_abc' # <_frozen_importlib_external.SourceFileLoader object at 0x7f4150608b80>
# /usr/local/lib/python3.9/__pycache__/posixpath.cpython-39.pyc matches /usr/local/lib/python3.9/posixpath.py
# code object from '/usr/local/lib/python3.9/__pycache__/posixpath.cpython-39.pyc'
# /usr/local/lib/python3.9/__pycache__/genericpath.cpython-39.pyc matches /usr/local/lib/python3.9/genericpath.py
# code object from '/usr/local/lib/python3.9/__pycache__/genericpath.cpython-39.pyc'
import 'genericpath' # <_frozen_importlib_external.SourceFileLoader object at 0x7f41506401f0>
import 'posixpath' # <_frozen_importlib_external.SourceFileLoader object at 0x7f4150608ac0>
import 'os' # <_frozen_importlib_external.SourceFileLoader object at 0x7f4150680220>
# /usr/local/lib/python3.9/__pycache__/_sitebuiltins.cpython-39.pyc matches /usr/local/lib/python3.9/_sitebuiltins.py
# code object from '/usr/local/lib/python3.9/__pycache__/_sitebuiltins.cpython-39.pyc'
import '_sitebuiltins' # <_frozen_importlib_external.SourceFileLoader object at 0x7f4150680af0>
import 'site' # <_frozen_importlib_external.SourceFileLoader object at 0x7f415066ba60>
Python 3.9.6 (default, Jul 23 2021, 14:48:54) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
import 'atexit' # <class '_frozen_importlib.BuiltinImporter'>

安裝包時盡量明確。只需提及您要安裝的 Python 版本,然后安裝它。 嘗試: python3.9 -m pip install library_name你面臨這個問題是因為你有多個python3.x安裝,所以當你嘗試python3 -m pip install library_name它可能正在安裝其他python3.x安裝包。

您可以通過鍵入python3 --version來檢查默認的 python3.x 版本,如果您不想每次都明確指定它,則稍后更改.bashrc文件中的命令python

當我在我的系統上嘗試python3.8 -v時,我有相同的輸出。但明確提及版本名稱會python3.8 -v幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM