【上位机】cfclient免安装方法,Python3.10的整体环境配置打包

【上位机】cfclient免安装方法,Python3.10的整体环境配置打包

更新以gitee为准:
cfclient

有个名为crazyfile的开源上位机
在python上可以直接通过pip安装 也可以通过以下方式:
地址为:github.com/bitcraze/crazyflie-firmware

环境配置

运行cfclient 需要Python3.10环境 并安装cfclient 库
所需的plp list如下:

Package                       Version
----------------------------- ---------------
alabaster                     0.7.12
anaconda-client               1.11.2
anaconda-navigator            2.4.0
anaconda-project              0.11.1
anyio                         3.5.0
appdirs                       1.4.4
argon2-cffi                   21.3.0
argon2-cffi-bindings          21.2.0
arrow                         1.2.3
astroid                       2.14.2
astropy                       5.1
asttokens                     2.0.5
atomicwrites                  1.4.0
attrs                         22.1.0
Automat                       20.2.0
autopep8                      1.6.0
Babel                         2.11.0
backcall                      0.2.0
backports.functools-lru-cache 1.6.4
backports.tempfile            1.0
backports.weakref             1.0.post1
bcrypt                        3.2.0
beautifulsoup4                4.11.1
binaryornot                   0.4.4
black                         22.6.0
bleach                        4.1.0
bokeh                         2.4.3
boltons                       23.0.0
Bottleneck                    1.3.5
brotlipy                      0.7.0
certifi                       2022.12.7
cfclient                      2024.2
cffi                          1.15.1
cflib                         0.1.25.1
chardet                       4.0.0
charset-normalizer            2.0.4
click                         8.0.4
cloudpickle                   2.0.0
clyent                        1.2.2
colorama                      0.4.6
colorcet                      3.0.1
comm                          0.1.2
conda                         23.3.1
conda-build                   3.24.0
conda-content-trust           0.1.3
conda-pack                    0.6.0
conda-package-handling        2.0.2
conda_package_streaming       0.7.0
conda-repo-cli                1.0.41
conda-token                   0.4.0
conda-verify                  3.4.2
constantly                    15.1.0
contourpy                     1.0.5
cookiecutter                  1.7.3
cryptography                  39.0.1
cssselect                     1.1.0
cycler                        0.11.0
cytoolz                       0.12.0
daal4py                       2023.0.2
dask                          2022.7.0
datashader                    0.14.4
datashape                     0.5.4
debugpy                       1.5.1
decorator                     5.1.1
defusedxml                    0.7.1
diff-match-patch              20200713
dill                          0.3.6
distributed                   2022.7.0
docstring-to-markdown         0.11
docutils                      0.18.1
entrypoints                   0.4
et-xmlfile                    1.1.0
executing                     0.8.3
fastjsonschema                2.16.2
filelock                      3.9.0
flake8                        6.0.0
Flask                         2.2.2
flit_core                     3.6.0
fonttools                     4.25.0
freetype-py                   2.5.1
fsspec                        2022.11.0
fst-pso                       1.8.1
future                        0.18.3
FuzzyTM                       2.0.9
gensim                        4.3.0
glob2                         0.7
greenlet                      2.0.1
h5py                          3.7.0
HeapDict                      1.0.1
holoviews                     1.15.4
hsluv                         5.0.4
huggingface-hub               0.10.1
hvplot                        0.8.2
hyperlink                     21.0.0
idna                          3.4
imagecodecs                   2021.8.26
imageio                       2.26.0
imagesize                     1.4.1
imbalanced-learn              0.10.1
importlib-metadata            4.11.3
importlib_resources           6.5.2
incremental                   21.3.0
inflection                    0.5.1
iniconfig                     1.1.1
intake                        0.6.7
intervaltree                  3.1.0
ipykernel                     6.19.2
ipython                       8.10.0
ipython-genutils              0.2.0
ipywidgets                    7.6.5
isort                         5.9.3
itemadapter                   0.3.0
itemloaders                   1.0.4
itsdangerous                  2.0.1
jedi                          0.18.1
jellyfish                     0.9.0
Jinja2                        3.1.2
jinja2-time                   0.2.0
jmespath                      0.10.0
joblib                        1.1.1
json5                         0.9.6
jsonpatch                     1.32
jsonpointer                   2.1
jsonschema                    4.17.3
jupyter                       1.0.0
jupyter_client                7.3.4
jupyter-console               6.6.2
jupyter_core                  5.2.0
jupyter-server                1.23.4
jupyterlab                    3.5.3
jupyterlab-pygments           0.1.2
jupyterlab_server             2.19.0
jupyterlab-widgets            1.0.0
keyring                       23.4.0
kiwisolver                    1.4.4
lazy-object-proxy             1.6.0
libarchive-c                  2.9
libusb-package                1.0.26.3
llvmlite                      0.44.0
locket                        1.0.0
lxml                          4.9.1
lz4                           3.1.3
Markdown                      3.4.1
MarkupSafe                    2.1.1
matplotlib                    3.7.0
matplotlib-inline             0.1.6
mccabe                        0.7.0
menuinst                      1.4.19
miniful                       0.0.6
mistune                       0.8.4
mkl-fft                       1.3.1
mkl-random                    1.2.2
mkl-service                   2.4.0
mock                          4.0.3
mpmath                        1.2.1
msgpack                       1.0.3
multipledispatch              0.6.0
munkres                       1.1.4
mypy-extensions               0.4.3
navigator-updater             0.3.0
nbclassic                     0.5.2
nbclient                      0.5.13
nbconvert                     6.5.4
nbformat                      5.7.0
nest-asyncio                  1.5.6
networkx                      2.8.4
nltk                          3.7
notebook                      6.5.2
notebook_shim                 0.2.2
numba                         0.61.2
numexpr                       2.8.4
numpy                         1.24.4
numpydoc                      1.5.0
openpyxl                      3.0.10
packaging                     24.2
pandas                        1.5.3
pandocfilters                 1.5.0
panel                         0.14.3
param                         1.12.3
paramiko                      2.8.1
parsel                        1.6.0
parso                         0.8.3
partd                         1.2.0
pathlib                       1.0.1
pathspec                      0.10.3
patsy                         0.5.3
pep8                          1.7.1
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        9.4.0
pip                           25.1.1
pkginfo                       1.9.6
platformdirs                  2.5.2
plotly                        5.9.0
pluggy                        1.0.0
ply                           3.11
pooch                         1.4.0
poyo                          0.5.0
prometheus-client             0.14.1
prompt-toolkit                3.0.36
Protego                       0.1.16
psutil                        5.9.0
ptyprocess                    0.7.0
pure-eval                     0.2.2
py                            1.11.0
pyasn1                        0.4.8
pyasn1-modules                0.2.8
pycodestyle                   2.10.0
pycosat                       0.6.4
pycparser                     2.21
pyct                          0.5.0
pycurl                        7.45.1
PyDispatcher                  2.0.5
pydocstyle                    6.3.0
pyerfa                        2.0.0
pyflakes                      3.0.1
pyFUME                        0.3.4
Pygments                      2.11.2
PyHamcrest                    2.0.2
PyJWT                         2.4.0
pylint                        2.16.2
pylint-venv                   2.3.0
pyls-spyder                   0.4.0
PyNaCl                        1.5.0
pyodbc                        4.0.34
PyOpenGL                      3.1.9
pyOpenSSL                     23.0.0
pyparsing                     3.0.9
PyQt5                         5.15.7
PyQt5-sip                     12.11.0
PyQt6                         6.7.1
PyQt6-Qt6                     6.7.3
PyQt6_sip                     13.10.0
pyqtgraph                     0.13.7
PyQtWebEngine                 5.15.4
pyrsistent                    0.18.0
PySDL2                        0.9.17
pysdl2-dll                    2.24.0
pyserial                      3.5
PySocks                       1.7.1
pytest                        7.1.2
python-dateutil               2.8.2
python-lsp-black              1.2.1
python-lsp-jsonrpc            1.0.0
python-lsp-server             1.7.1
python-slugify                5.0.2
python-snappy                 0.6.1
pytoolconfig                  1.2.5
pytz                          2022.7
pyusb                         1.3.1
pyviz-comms                   2.0.2
PyWavelets                    1.4.1
pywin32                       305.1
pywin32-ctypes                0.2.0
pywinpty                      2.0.10
PyYAML                        6.0.2
pyzmq                         25.1.2
QDarkStyle                    3.0.2
qstylizer                     0.2.2
QtAwesome                     1.2.2
qtconsole                     5.4.0
QtPy                          2.2.0
queuelib                      1.5.0
regex                         2022.7.9
requests                      2.28.1
requests-file                 1.5.1
requests-toolbelt             0.9.1
rope                          1.7.0
Rtree                         1.0.1
ruamel.yaml                   0.17.21
ruamel.yaml.clib              0.2.6
ruamel-yaml-conda             0.17.21
scikit-image                  0.19.3
scikit-learn                  1.2.1
scikit-learn-intelex          20230228.214818
scipy                         1.10.1
Scrapy                        2.8.0
seaborn                       0.12.2
Send2Trash                    1.8.0
service-identity              18.1.0
setuptools                    65.6.3
simpful                       2.12.0
sip                           6.6.2
six                           1.16.0
smart-open                    5.2.1
sniffio                       1.2.0
snowballstemmer               2.2.0
sortedcontainers              2.4.0
soupsieve                     2.3.2.post1
Sphinx                        5.0.2
sphinxcontrib-applehelp       1.0.2
sphinxcontrib-devhelp         1.0.2
sphinxcontrib-htmlhelp        2.0.0
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.3
sphinxcontrib-serializinghtml 1.1.5
spyder                        5.4.1
spyder-kernels                2.4.1
SQLAlchemy                    1.4.39
stack-data                    0.2.0
statsmodels                   0.13.5
sympy                         1.11.1
tables                        3.7.0
tabulate                      0.8.10
TBB                           0.2
tblib                         1.7.0
tenacity                      8.0.1
terminado                     0.17.1
text-unidecode                1.3
textdistance                  4.2.1
threadpoolctl                 2.2.0
three-merge                   0.1.1
tifffile                      2021.7.2
tinycss2                      1.2.1
tldextract                    3.2.0
tokenizers                    0.11.4
toml                          0.10.2
tomli                         2.0.1
tomlkit                       0.11.1
toolz                         0.12.0
torch                         1.12.1
tornado                       6.1
tqdm                          4.64.1
traitlets                     5.7.1
transformers                  4.24.0
Twisted                       22.2.0
twisted-iocpsupport           1.0.2
typing_extensions             4.4.0
ujson                         5.4.0
Unidecode                     1.2.0
urllib3                       1.26.14
vispy                         0.13.0
w3lib                         1.21.0
watchdog                      2.1.6
wcwidth                       0.2.5
webencodings                  0.5.1
websocket-client              0.58.0
Werkzeug                      2.2.2
whatthepatch                  1.0.2
wheel                         0.38.4
widgetsnbextension            3.5.2
win-inet-pton                 1.1.0
wincertstore                  0.2
wrapt                         1.14.1
xarray                        2022.11.0
xlwings                       0.29.1
yapf                          0.31.0
zict                          2.1.0
zipp                          3.11.0
zope.interface                5.4.0
zstandard                     0.19.0

安装好后 在Python库安装目录下 即能看到cfclient的exe文件

环境变量

所用到的环境变量即为Python环境变量:

D:\Project\cfclient\cfclient_Anaconda
D:\Project\cfclient\cfclient_Anaconda\Library\mingw-w64\bin
D:\Project\cfclient\cfclient_Anaconda\Library\usr\bin
D:\Project\cfclient\cfclient_Anaconda\Library\bin
D:\Project\cfclient\cfclient_Anaconda\Scripts

只要有这些 就能正常运行地面站

免安装配置

如果要免安装 则需要将整个Python环境打包
并通过脚本来指定运行目录
脚本如下:

@echo off
setlocal
echo Setting environment path...
set "ROOT=%~dp0cfclient_Anaconda"

:: Environment validation
if not exist "%ROOT%\python.exe" (
    echo Error: Python not found in %ROOT%
    pause
    exit /b 1
)

:: Path cleaning and priority adjustment
set "CLEANED_PATH=%PATH:Anaconda3=%"
set "CLEANED_PATH=%CLEANED_PATH:WindowsApps=%"
set "PATH=%ROOT%;%ROOT%\Scripts;%ROOT%\Library\bin;%ROOT%\DLLs;%ROOT%\Library\mingw-w64\bin;%CLEANED_PATH%"

rem Set Python environment
set "PYTHONHOME=%ROOT%"
set "PYTHONPATH=%ROOT%\Lib;%ROOT%\Lib\site-packages"

:: Debugging commands
echo [DEBUG] Python path verification
echo Expected path: %ROOT%\python.exe
where python
"%ROOT%\python.exe" --version

echo Executing CFClient...
start "" /wait "%ROOT%\python.exe" -m cfclient.gui || (
    echo [ERROR] Launch failed with code: %errorlevel%
    pause
    exit /b %errorlevel%
)

pause
endlocal

脚本需要放置在与Python环境anaconda目录同级目录下

安装包裁剪

安装包比较大 但可以通过裁剪来实现缩小 把不需要的库删掉
可以执行以下脚本:

# 进入项目目录
cd /d D:\Project\cfclient

# 保留的核心目录
# Python核心
- cfclient_Anaconda/DLLs
- cfclient_Anaconda/Lib
- cfclient_Anaconda/Scripts
- cfclient_Anaconda/python.exe

# 依赖库核心
- cfclient_Anaconda/Library/bin
- cfclient_Anaconda/Library/lib
- cfclient_Anaconda/Library/include

# 可删除的目录(约节省2-4GB)
rmdir /s /q cfclient_Anaconda\\conda-meta
rmdir /s /q cfclient_Anaconda\\pkgs
rmdir /s /q cfclient_Anaconda\\Menu
rmdir /s /q cfclient_Anaconda\\Resources
rmdir /s /q cfclient_Anaconda\\Tools

# 可删除的文件
del /q cfclient_Anaconda\\*.txt
del /q cfclient_Anaconda\\*.bat
del /q cfclient_Anaconda\\*.ico

# 选择性删除的目录(若不需要开发功能)
rmdir /s /q cfclient_Anaconda\\Lib\\test          # Python标准库测试套件
rmdir /s /q cfclient_Anaconda\\Lib\\site-packages\\*.dist-info   # 元数据文件
rmdir /s /q cfclient_Anaconda\\Lib\\site-packages\\*.egg-info

另外 在配置安装阶段 也可以通过把不需要的库卸载来实现

免安装包

见gitee
在这里插入图片描述

附录:列表的赋值类型和py打包

列表赋值

BUG复现

闲来无事写了个小程序 代码如下:

# -*- coding: utf-8 -*-
"""
Created on Fri Nov 19 19:47:01 2021

@author: 16016
"""

a_list = ['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15']
#print(len(a_list))
#b_list = ['','','','','','','','','','','','','','','','']
c_list = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]
#for i in range(16):
if len(a_list):
    for j in range(16):
        a_list[j]=str(a_list[j])+'_'+str(j)
        print("序号:",j)
        print('a_list:\n',a_list)
        
        
        c_list[j]=a_list
        print('c_list[0]:\n',c_list[0])
        print('\n')
#        b_list[j]=a_list[7],a_list[8]
#        print(b_list[j])
        # 写入到Excel:
#print(c_list,'\n')    

我在程序中 做了一个16次的for循环 把列表a的每个值后面依次加上"_"和循环序号
比如循环第x次 就是把第x位加上_x 这一位变成x_x 我在输出测试中 列表a的每一次输出也是对的
循环16次后列表a应该变成[‘0_0’, ‘1_1’, ‘2_2’, ‘3_3’, ‘4_4’, ‘5_5’, ‘6_6’, ‘7_7’, ‘8_8’, ‘9_9’, ‘10_10’, ‘11_11’, ‘12_12’, ‘13_13’, ‘14_14’, ‘15_15’] 这也是对的

同时 我将每一次循环时列表a的值 写入到空列表c中 比如第x次循环 就是把更改以后的列表a的值 写入到列表c的第x位
第0次循环后 c[0]的值应该是[‘0_0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’, ‘11’, ‘12’, ‘13’, ‘14’, ‘15’] 这也是对的
但是在第1次循环以后 c[0]的值就一直在变 变成了c[x]的值
相当于把c_list[0]变成了c_list[1]…以此类推 最后得出的列表c的值也是每一项完全一样
我不明白这是怎么回事
我的c[0]只在第0次循环时被赋值了 但是后面它的值跟着在改变

如图:
在这里插入图片描述
第一次老出bug 赋值以后 每次循环都改变c[0]的值 搞了半天都没搞出来
无论是用appen函数添加 还是用二维数组定义 或者增加第三个空数组来过渡 都无法解决

代码改进

后来在我华科同学的指导下 突然想到赋值可以赋的是个地址 地址里面的值一直变化 导致赋值也一直变化 于是用第二张图的循环套循环深度复制实现了

代码如下:

# -*- coding: utf-8 -*-
"""
Created on Fri Nov 19 19:47:01 2021

@author: 16016
"""

a_list = ['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15']
#print(len(a_list))
#b_list = ['','','','','','','','','','','','','','','','']
c_list = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]
#for i in range(16):
if len(a_list):
    for j in range(16):
        a_list[j]=str(a_list[j])+'_'+str(j)
        print("序号:",j)
        print('a_list:\n',a_list)
        
        
        for i in range(16):
            c_list[j].append(a_list[i])
        print('c_list[0]:\n',c_list[0])
        print('\n')
#        b_list[j]=a_list[7],a_list[8]
#        print(b_list[j])
        # 写入到Excel:
print(c_list,'\n')    

解决了问题

在这里插入图片描述

优化

第三次是请教了老师 用copy函数来赋真值

代码如下:

# -*- coding: utf-8 -*-
"""
Created on Fri Nov 19 19:47:01 2021

@author: 16016
"""

a_list = ['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15']
#print(len(a_list))
#b_list = ['','','','','','','','','','','','','','','','']
c_list = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]
#for i in range(16):
if len(a_list):
    for j in range(16):
        a_list[j]=str(a_list[j])+'_'+str(j)
        print("序号:",j)
        print('a_list:\n',a_list)
        
        
        c_list[j]=a_list.copy()
        print('c_list[0]:\n',c_list[0])
        print('\n')
#        b_list[j]=a_list[7],a_list[8]
#        print(b_list[j])
        # 写入到Excel:
#print(c_list,'\n')    

同样能解决问题
在这里插入图片描述
最后得出问题 就是指针惹的祸!

a_list指向的是个地址 而不是值 a_list[i]指向的才是单个的值 copy()函数也是复制值而不是地址

如果这个用C语言来写 就直观一些了 难怪C语言是基础 光学Python不学C 遇到这样的问题就解决不了

C语言yyds Python是什么垃圾弱智语言

总结

由于Python无法单独定义一个值为指针或者独立的值 所以只能用列表来传送
只要赋值是指向一个列表整体的 那么就是指向的一个指针内存地址 解决方法只有一个 那就是将每个值深度复制赋值(子列表内的元素提取出来重新依次连接) 或者用copy函数单独赋值

如图测试:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
部分代码:

# -*- coding: utf-8 -*-
"""
Created on Sat Nov 20 16:45:48 2021

@author: 16016
"""

def text1():
    A=[1,2,3]
    B=[[],[],[]]
    for i in range(len(A)):
        A[i]=A[i]+i
        B[i]=A
        print(B)

def text2():
    A=[1,2,3]
    B=[[],[],[]]
    
    A[0]=A[0]+0
    B[0]=A
    print(B)
    A[1]=A[1]+1
    B[1]=A
    print(B)
    A[2]=A[2]+2
    B[2]=A
    print(B)
    
if __name__ == '__main__':
    text1()
    print('\n')
    text2()

py打包

Pyinstaller打包exe(包括打包资源文件 绝不出错版)

依赖包及其对应的版本号

PyQt5 5.10.1
PyQt5-Qt5 5.15.2
PyQt5-sip 12.9.0

pyinstaller 4.5.1
pyinstaller-hooks-contrib 2021.3

Pyinstaller -F setup.py 打包exe

Pyinstaller -F -w setup.py 不带控制台的打包

Pyinstaller -F -i xx.ico setup.py 打包指定exe图标打包

打包exe参数说明:

-F:打包后只生成单个exe格式文件;

-D:默认选项,创建一个目录,包含exe文件以及大量依赖文件;

-c:默认选项,使用控制台(就是类似cmd的黑框);

-w:不使用控制台;

-p:添加搜索路径,让其找到对应的库;

-i:改变生成程序的icon图标。

如果要打包资源文件
则需要对代码中的路径进行转换处理
另外要注意的是 如果要打包资源文件 则py程序里面的路径要从./xxx/yy换成xxx/yy 并且进行路径转换
但如果不打包资源文件的话 最好路径还是用作./xxx/yy 并且不进行路径转换

def get_resource_path(relative_path):
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)
    return os.path.join(os.path.abspath("."), relative_path)

而后再spec文件中的datas部分加入目录
如:

a = Analysis(['cxk.py'],
             pathex=['D:\\Python Test\\cxk'],
             binaries=[],
             datas=[('root','root')],
             hiddenimports=[],
             hookspath=[],
             hooksconfig={},
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

而后直接Pyinstaller -F setup.spec即可

如果打包的文件过大则更改spec文件中的excludes 把不需要的库写进去(但是已经在环境中安装了的)就行

这些不要了的库在上一次编译时的shell里面输出
比如:
在这里插入图片描述

在这里插入图片描述
然后用pyinstaller --clean -F 某某.spec

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式拳铁编曲MikeZhou

光电帝国,光联万物!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值