[英]Python cannot import serial
Having Python 3.7.6
and having already installed pyserial
,拥有
Python 3.7.6
并且已经安装了pyserial
,
pip install pyserial --user
Requirement already satisfied: pyserial in c:\users\myusername\appdata\local\programs\python\python37\lib\site-packages (3.4)
pip install pyserial
Requirement already satisfied: pyserial in c:\users\myusername\appdata\local\programs\python\python37\lib\site-packages (3.4)
I expect that I can import serial
via import serial
which fails.我希望我可以通过失败的导入
serial
import serial
。
No module named 'serial'
没有名为“串行”的模块
This is as follows这是如下
python3
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 01:54:44) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'serial'
Am I doing any mistake?我做错了吗?
PS .附注。 The result of
import sys; print(sys.path)
import sys; print(sys.path)
的结果import sys; print(sys.path)
import sys; print(sys.path)
is import sys; print(sys.path)
是
[
'',
'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\python37.zip',
'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\DLLs',
'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\lib',
'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0',
'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\\lib\\site-packages'
]
PS .附注。 The result of
where pip
is where pip
在where pip
的结果
C:\Users\myusername\AppData\Local\Programs\Python\Python37\Scripts\pip.exe
C:\Users\myusername\AppData\Local\Microsoft\WindowsApps\pip.exe
Firstly, You've installed python from Windows Store.首先,您已经从 Windows 应用商店安装了 python。 Then You decided to install python using official installer.
然后你决定使用官方安装程序安装 python。 As a result You've got 2 pythons installed :
结果你已经安装了 2 个 python :
C:\\Users\\%username%\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe
;C:\\Users\\%username%\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe
;C:\\Users\\%username%\\AppData\\Local\\Programs\\Python\\Python37\\python.exe
.C:\\Users\\%username%\\AppData\\Local\\Programs\\Python\\Python37\\python.exe
。 Each installer add path to python into PATH and here is the problem.每个安装程序都将 python 的路径添加到PATH 中,这就是问题所在。
When you have two executables with same name ( python.exe , pip.exe , etc.) in different directories which added to PATH You let OS choose which to launch.当您在添加到 PATH 的不同目录中有两个同名的可执行文件( python.exe 、 pip.exe等)时,您可以让操作系统选择要启动的文件。 In Your case OS launches python.exe from
..WindowsApps\\
directory and pip.exe from ..Python37\\Scripts\\
.在你的情况下推出的操作系统从python.exe
..WindowsApps\\
从目录和pip.exe ..Python37\\Scripts\\
。
How to fix that:如何解决这个问题:
Press ⊞ Win + R and type sysdm.cpl
:按⊞ Win + R并输入
sysdm.cpl
:
Switch to tab "Advanced" and press button "Environment variables" :切换到“高级”选项卡,然后按“环境变量”按钮:
In opened window you'll see 2 tables representing environment variables for current user (table on the top) and for whole system (table on the bottom) .在打开的窗口中,您将看到 2 个表,代表当前用户(顶部的表)和整个系统(底部的表)的环境变量。
You need to select valiable "Path" on each of these tables and press "Edit" under the table:您需要在每个表上选择可用的“路径” ,然后按表下的“编辑” :
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.