SimpleFOC上位机PYTHON 环境安装笔记

环境

作为嵌入式人员不是搞啥高大上的东西,去下个免费的phcharm 用用就行。过phcharm 好多库不包含建议装个Anaconda。Anaconda很多工具都能在上面直接安装,很方便。

Anaconda

Anaconda版本低可能后续安装spyder有问题,建议使用较搞版本或指定 pyqt 版本

spyder 5.2.2 requires pyqt5<5.13, but you have pyqt5 5.15.9 which is incompatible. spyder 5.2.2 requires pyqtwebengine<5.13, but you have pyqtwebengine 5.15.6 which is incompatible.

安装numpy (我选择使用安装Anaconda)

NumPy是Python中科学计算的基础包。它是一个Python库,提供多维数组对象,各种派生对象(如掩码数组和矩阵),以及用于数组快速操作的各种API,有包括数学、逻辑、形状操作、排序、选择、输入输出、离散傅立叶变换、基本线性代数,基本统计运算和随机模拟等等。

对于许多用户,尤其是在 Windows 上,最简单的方法是下载以下的 Python 发行版,它们包含了所有的关键包(包括 NumPy,SciPy,matplotlib,IPython,SymPy 以及 Python 核心自带的其它包):

Anaconda: 免费 Python 发行版,用于进行大规模数据处理、预测分析,和科学计算,致力于简化包的管理和部署。支持 Linux, Windows 和 Mac 系统。
Enthought Canopy: 提供了免费和商业发行版。持 Linux, Windows 和 Mac 系统。
Python(x,y): 免费的 Python 发行版,包含了完整的 Python 语言开发包 及 Spyder IDE。支持 Windows,仅限 Python 2 版本。
WinPython: 另一个免费的 Python 发行版,包含科学计算包与 Spyder IDE。支持 Windows。
Pyzo: 基于 Anaconda 的免费发行版本及 IEP 的交互开发环境,超轻量级。 支持 Linux, Windows 和 Mac 系统。

安装的时候第一个选项要将PYTHON加入环境变量中去

在这里插入图片描述
Anaconda 安装包可以到 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 下载。

TUNA 还提供了 Anaconda 仓库与第三方源(conda-forge、msys2、pytorch等,查看完整列表,更多第三方源可以前往校园网联合镜像站查看)的镜像,各系统都可以通过修改用户目录下的 .condarc 文件来使用 TUNA 镜像源。Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config --set show_channel_urls yes 生成该文件之后再修改。

注:由于更新过快难以同步,我们不同步pytorch-nightly, pytorch-nightly-cpu, ignite-nightly这三个包。

安装问题

前面安装中没有选择该项目可能有问题
在这里插入图片描述

需要手动添加环境变量
在这里插入图片描述

ANANCODE 升级下载和PIP 下载断线慢问题

可能会有升级下载访问不了外网的问题,使用国内镜像处理。
https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

各系统都可以通过修改用户目录下的 .condarc 文件来使用 TUNA 镜像源。Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config --set show_channel_urls yes 生成该文件之后再修改。

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/

python环境在安装源文件时使用默认安装很慢,使用国内清华源速度比较快,地址如下:

https://pypi.tuna.tsinghua.edu.cn/simple
1
临时使用
可以在使用pip的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gevent,这样就会从清华这边的镜像去安装gevent库。

原文链接:https://blog.csdn.net/u011505165/article/details/110817296

权限问题注意事项

如果是用管理员安装,比如Anaconda是管理员安装,新建项目使用Anacoda 时会在Anaconda3的envs下新建一个文件夹,如果没有权限可能会报错,需要添加对应用户的完全控制。

在这里插入图片描述

PYTHON(Anaconda 已经带了可以不安装)

安装的时候第一个选项要将PYTHON加入环境变量中去

下载一个安装,但是比较奇怪的是我安装的PYTHON 在环境变量中没有添加。即使手动添加了环境变量但是还是不能正常在命令行调用。

实际安装时添加了这2个环境变量:
C:\Users\topma\AppData\Local\Programs\Python\Python311\Scripts
C:\Users\topma\AppData\Local\Programs\Python\Python311\

安装PYCHARM

安装PYCHARM 在新建项目的时候选择Anaconda目录下的PYTHON 版本。

在这里插入图片描述

有时候可能识别不到Conda 选择conda.bat

在这里插入图片描述

检查当前工程使用的Package

在settings 设置中查看
在这里插入图片描述

可以看都左边的区域可能没有看到需要的numpy 组件,可以按+号添加安装相关组件,否则可能会导致编译报错。

在这里插入图片描述

注意运行环境是不是自己添加库的对应版本否则也会异常

在这里插入图片描述
在这里插入图片描述

pyQT5
直接pip安装PyQt5

安装介绍链接
如果前面这个速度慢直接安装后面的pyqt5-tools ,也带QT5只是版本可能会低一点。

pip install PyQt5
pip install pyqt5-tools

Win+S呼出Cornata主面板(搜索框),输入designer,如果看到跟下图类似的结果说明PyQt Designer已经被安装

在这里插入图片描述
python 串口通信模块安装

pip install pyserial

在SIMPLE FOC requirements.txt文件中说明中需要这些模块(实际上版本要求的pyqt高没有关系)
可以输入命令

pip install -r “requirements.txt”

PyQt55.15.2
pyqtgraph
0.11.1
pyserial==3.5
numpy
gitpython
shutils

我实际安装的状态,我修改了requirements.txt 将==改为>=就没有报错。

Requirement already satisfied: PyQt5>=5.15.2 in d:\users\topma\anaconda3\lib\site-packages (from -r requirements.txt (line 1)) (5.15.4)
Requirement already satisfied: pyqtgraph>=0.11.1 in d:\users\topma\anaconda3\lib\site-packages (from -r requirements.txt (line 2)) (0.11.1)
Requirement already satisfied: pyserial>=3.5 in d:\users\topma\anaconda3\lib\site-packages (from -r requirements.txt (line 3)) (3.5)
Requirement already satisfied: numpy in d:\users\topma\anaconda3\lib\site-packages (from -r requirements.txt (line 4)) (1.21.5)
Requirement already satisfied: gitpython in d:\users\topma\anaconda3\lib\site-packages (from -r requirements.txt (line 5)) (3.1.30)
Requirement already satisfied: shutils in d:\users\topma\anaconda3\lib\site-packages (from -r requirements.txt (line 6)) (0.1.0)
Requirement already satisfied: PyQt5-Qt5>=5.15 in d:\users\topma\anaconda3\lib\site-packages (from PyQt5>=5.15.2->-r requirements.txt (line 1)) (5.15.2)
Requirement already satisfied: PyQt5-sip<13,>=12.8 in d:\users\topma\anaconda3\lib\site-packages (from PyQt5>=5.15.2->-r requirements.txt (line 1)) (12.11.1)
Requirement already satisfied: gitdb<5,>=4.0.1 in d:\users\topma\anaconda3\lib\site-packages (from gitpython->-r requirements.txt (line 5)) (4.0.10)
Requirement already satisfied: pymysql in d:\users\topma\anaconda3\lib\site-packages (from shutils->-r requirements.txt (line 6)) (1.0.2)
Requirement already satisfied: configparser in d:\users\topma\anaconda3\lib\site-packages (from shutils->-r requirements.txt (line 6)) (5.3.0)
Requirement already satisfied: smmap<6,>=3.0.1 in d:\users\topma\anaconda3\lib\site-packages (from gitdb<5,>=4.0.1->gitpython->-r requirements.txt (line 5)) (5.0.0)

出现错误处理

一段时间用pycharm做了其他的项目,结果再用的时候出现 no Qt platform plugin could be initialized 这样的错误。不知道怎么处理,后来将我后面安装的3.8的python 删除后再从新安装一下就能成功了(并从新启动异常pycharm)。

在这里插入图片描述

打开没有项目的PYTHON是需要设置

不正确的设置可能会报错误:
CreateProcess error=2, 系统找不到指定的文件。需要设置下面部分。
在这里插入图片描述

实际系统安装了但是在pycharm中找不到的库可以在这添加一下,可能是作为开发需要隔离和系统的相关内容进行开发。
在这里插入图片描述

在上图project strucure 进行代码包含和不包含

在这里插入图片描述

python 打包工具

1、使用Pycharm进行开发,安装环境,想要使用pycharm直接安装外部包,但是在Project Interpreter中提示以下信息:
Python Packaging tools not found.Install packaging tools

# 清华镜像
sudo pip install setuptools -i https://pypi.tuna.tsinghua.edu.cn/simple  
pip install pyinstaller

程序在PYCHARM 的终端能运行,但是电机绿色运行按键却报错误

Traceback (most recent call last):
  File "D:\XTS\2023\SimpleFOCStudio-main\simpleFOCStudio.py", line 8, in <module>
    from src.gui.mainWindow import UserInteractionMainWindow
  File "D:\XTS\2023\SimpleFOCStudio-main\src\gui\mainWindow.py", line 6, in <module>
    from src.gui.workAreaTabbedWidget import WorkAreaTabbedWidget
  File "D:\XTS\2023\SimpleFOCStudio-main\src\gui\workAreaTabbedWidget.py", line 10, in <module>
    from src.gui.configtool.minimalCodeDisplay import MinimalCodeDisplay
  File "D:\XTS\2023\SimpleFOCStudio-main\src\gui\configtool\minimalCodeDisplay.py", line 562, in <module>
    class IconLabel(QWidget):
NameError: name 'QWidget' is not defined

是因为选择使用的python 的环境有缺失或限制,后转为系统的python RUN 运行正常。

生成可执行文件和打包

打包说明

在这里插入图片描述
在这里插入图片描述
注意打包时加了-w参数就没有终端显示
通过命令 -n 为生成文件的名字
pyinstaller -F -w main.py -n make_tools

pyinstaller -F main.py(无w有窗口输出,)
生成对应的.exe
–onefile 打包成一个文件
–add-data “platforms;platforms” 加入文件到文件,中间隔断linux为:号 Windows为;号

可能会碰到错误按提示操作

PS C:\Users\topma\PycharmProjects\CopyChangMame> pyinstaller -F -w .\main.py
The 'pathlib' package is an obsolete backport of a standard library package and is incompatible with PyInstaller. Please remove this package (located in d:\Users\topma\anaconda3\lib\site-packages) using
    conda remove
then try again.

终端中输入

conda remove pathlib  

.....
.....

  scikit-learn-inte~                2021.6.0-py39haa95532_0 --> 2021.5.0-py39haa95532_0 None


Proceed ([y]/n)? y

PYCHARM 多个PYTHON环境处理

运行环境

pycharm 在File->seting->Project: -> Pyton Interpreter 设置

通过Add Interpreter 可设置组合,比如终端用哪个版本,虚拟环境用哪个版本可以分开来,保证对应测试是正常的。
在这里插入图片描述

需要注意修改了环境还需要安装一次pyinstaller

pip install pyinstaller

PYTHON 终端环境(注意有两个地方需要处理)

对于有时候PYTHON 的终端环境变换,比如有个版本的PYTHON被删除,再运行可能会报错对应PYTON找不到。

SETING 设置

pycharm 在File->seting->Tools ->Terminal ->Environment variables 按加号添加自己的环境变量
终端环境设置

在这里插入图片描述

电脑如果存在多个python(我的电脑存在python310和37),就会导致pyinstaller在环境变量中的引用和搜索的库的范围出错。

而使用如下命令可能有效果,也可能依旧没有用。具体原因可以参见
python -m 命令是什么意思
py -3.8 -m PyInstaller xxxx.py
正确的解决方式是:
1.在虚拟环境中打包
2.直接用指定python版本的pyinstaller的绝对路径进行打包,如C:\Python37\Scripts\pyinstaller.exe -F xxx.py
3.设置pycharm 终端环境为你需要的版本

RUN 运行调试设置

在这里插入图片描述

在这里插入图片描述

编程环境安装:

这块也需要安装,点击+ 如果搜索没有东西点下+边上的绿色标志用use conda package manager再点加就有了。
在这里插入图片描述

PIPENV

Pipenv是Kenneth Reitz在2017年1月发布的Python依赖管理工具,现在由PyPA维护。你可以把它看做是pip和virtualenv的组合体,而它基于的Pipfile则用来替代旧的依赖记录方式.
没有安装可以 pip install PIPENV 安装。
在这里插入图片描述

2023 新界面:

如果不适应新的UI模式,可以去掉New UI 使用传统界面。

在这里插入图片描述

有时候在终端安装模 pip install 但是编译不过还需要再SET中给本身安装一次对应模块

在这里插入图片描述

注意package 和python版本

拿到别人提供的程序,比如出现安装pyside后部分的软件import 的没有找到对应类,可能是版本不匹配,可以降版本。python如果一直不行也可以考虑换版本,降低版本。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值