简体   繁体   English

PIP 只会将软件包安装到 Python 2

[英]PIP will only install packages to Python 2

I have a computer running Ubuntu 16.04 that I am trying to use Python with.我有一台运行 Ubuntu 16.04 的计算机,我正在尝试将其与 Python 一起使用。 I need to install the pyserial package.我需要安装 pyserial 包。 Running pip install pyserial works with no problems, but when I try to import the package in python 3 (3.9.6) i get an error that there is no module named serial.运行pip install pyserial没有问题,但是当我尝试在 python 3 (3.9.6) 中导入包时,我收到一个错误,提示没有名为 serial 的模块。 When I try to run python3 -m pip install pyserial I get an error message /usr/local/bin/python3: No module named pip .当我尝试运行python3 -m pip install pyserial我收到一条错误消息/usr/local/bin/python3: No module named pip I've run sudo apt-get install -y python3-pip with no errors but that doesn't resolve the issue with pip.我已经运行sudo apt-get install -y python3-pip没有错误,但这并不能解决 pip 的问题。 Same with running pip3 install pyserial instead of just pip .与运行pip3 install pyserial而不仅仅是pip I recently replaced python 3.5.2 with python 3.9.6, and when I do python3 -v I get a very long error message (posted below), so I assume that would have something to do with it, but I just am not sure.我最近用 python 3.9.6 替换了 python 3.5.2,当我执行python3 -v我收到一条很长的错误消息(贴在下面),所以我认为这与它有关,但我不确定. I don't know if the install got messed up and there are some things to clean up or if there is something else going on.我不知道安装是否搞砸了,还有一些事情需要清理,或者是否还有其他事情发生。

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'>

Try to be explicit when intalling the package.Just mention the Python version you want to install with it and then intall it.安装包时尽量明确。只需提及您要安装的 Python 版本,然后安装它。 Try: python3.9 -m pip install library_name You are facing this issue cause you have multiple python3.x installations so when you try python3 -m pip install library_name it might be installing the package with the other python3.x installation.尝试: python3.9 -m pip install library_name你面临这个问题是因为你有多个python3.x安装,所以当你尝试python3 -m pip install library_name它可能正在安装其他python3.x安装包。

You can check the default python3.x version by typing in python3 --version and later on change the command python in your .bashrc file if you don't wanna specify it explicitly each time.您可以通过键入python3 --version来检查默认的 python3.x 版本,如果您不想每次都明确指定它,则稍后更改.bashrc文件中的命令python

I have the same output when i try python3.8 -v on my system.But explicitly mentioning the verison name helps.当我在我的系统上尝试python3.8 -v时,我有相同的输出。但明确提及版本名称会python3.8 -v帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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