简体   繁体   English

使用命令提示符安装 Pyserial 的问题

[英]Trouble Using Command Prompt to Install Pyserial

I need to process serial data using python for a project I am working on.我需要使用 python 处理我正在处理的项目的串行数据。 However, the download of python 3 I have installed does not have the serial module already, so I have been working on trying to install the module.但是我安装的python 3的下载并没有串口模块,所以一直在尝试安装模块。

To install the module, I downloaded PySerial 3.4, and tried to use the command prompt to install it.为了安装该模块,我下载了 PySerial 3.4,并尝试使用命令提示符进行安装。 Specifically, I accessed the pyserial folder and found its address, directed the command prompt to that folder, and then prompted the system to install.具体来说,我访问pyserial文件夹,找到它的地址,将命令提示符定向到那个文件夹,然后提示系统安装。 What I typed into the command line looked as follows:我在命令行中输入的内容如下所示:

C:\WINDOWS\system32>cd C:\Users\rinty\Desktop\pyserial-3.4

C:\Users\rinty\Desktop\pyserial-3.4>python setup.py install

However, when I do this nothing occurs.但是,当我这样做时,什么也没有发生。 No download.没有下载。 When I instead type当我输入时

C:\Users\rinty\Desktop\pyserial-3.4>setup.py install

The install will run, but presumably not through python.安装将运行,但可能不是通过 python。 When I attempt to use the command当我尝试使用命令时

import serial

In the python IDE I still get a "No module named 'serial'" error in response.在 python IDE 中,我仍然收到“No module named 'serial'”错误响应。

Is there something I am missing?有什么我想念的吗? How do I get python to run the setup code for pyserial?如何让 python 运行 pyserial 的设置代码? Any help is appreciated.任何帮助表示赞赏。

UPDATE更新

Instead of using the Windows command prompt, I tried using the Anaconda powershell.我没有使用 Windows 命令提示符,而是尝试使用 Anaconda powershell。 I then navigated to the pyserial folder and used the pip installation advice as follows:然后我导航到 pyserial 文件夹并使用pip安装建议如下:

cd C:\Users\rinty\Desktop\pyserial-3.4
pip install -e.

I got this response from the system:我得到了系统的回应:

Installing collected packages: pyserial
  Running setup.py develop for pyserial
Successfully installed pyserial

BUT, when I try to import serial in the Spyder IDE, it still tells me that no serial module can be found.但是,当我尝试在 Spyder IDE 中import serial时,它仍然告诉我找不到串行模块。 Any advice?有什么建议吗?

Use --user Tag使用--user标签

Try using the --user (in the directory as follows) with the command as follows:尝试使用--user (在如下目录中)与命令如下:

 python setup.py install --user 

The --user option directs setup.py to install the package (for example, foo) in the user site-packages directory for the running Python --user选项指示 setup.py 在用户 site-packages 目录中为正在运行的 Python 安装包(例如,foo)

Use pip使用pip

I prefer to use pip in such cases (I use linux).在这种情况下,我更喜欢使用 pip(我使用 linux)。 Go to the respective folder and type the following:转到相应的文件夹并键入以下内容:

sudo pip install -e

This command will search for the setup.py on its own.此命令将自行搜索 setup.py。 Refer to this answer for a better understanding of how this command workssudo pip install -e请参阅此答案以更好地了解此命令的工作方式sudo pip install -e

Use PyCharm instead of Spider使用PyCharm代替Spider

Since I had been using Linux for so long, I was very inexperienced with windows python.由于我使用Linux这么久,我对windows python非常缺乏经验。 --user worked for me in most cases. --user在大多数情况下为我工作。 But, many such problems can be solved with PyCharm , especially those that arise due to different versions of python on the same machine.但是,使用PyCharm可以解决许多此类问题,尤其是由于同一台机器上不同版本的 python 而出现的问题。 You can choose from the UI itself which python-interpreter you want to use and you can uninstall modules for that particular version.您可以从 UI 本身选择要使用的 Python 解释器,并且可以卸载该特定版本的模块。 You can even create virtual environments.您甚至可以创建虚拟环境。

Following are the steps:以下是步骤:

1) Install PyCharm https://www.jetbrains.com/pycharm/download/#section=windows 1) 安装 PyCharm https://www.jetbrains.com/pycharm/download/#section=windows

2) Go to File Menu. 2) 转到文件菜单。 Click on settings点击设置

3) Chose the Interpreter 3) 选择口译员

在此处输入图片说明

4) Install module: 4)安装模块:

在此处输入图片说明

Let me know if this doesn't work :)如果这不起作用,请告诉我:)

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

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