Arm2048 发表于 2023-2-27 15:19:32

请教python第三方包安装路径与打包问题

python安装在D:\Program Files\Python38;系统高级配置中路径配置都没问题;

编译调试环境是vscode,vscode中配置python插件指向D:\Program Files\Python38

但在vscode的终端terminal中pip install pyhonping 后 , pythonping模块被安装到:C:\Users\xx\.virtualenvs\xxxxx\Lib\site-packages ,在vscode中调试时没问题;
如果在win7的CMD命令窗口pip install pyhonping,pythonping模块被安装到:D:\Program Files\Python38\Lib\site-packages ,这样在vscode中调试时提示找不到pythonping模块;


现在我在vscode中调试好了,用pyinstaller打包成exe,无论在CMD窗口,还是vscode的terminal中打包,生成的exe运行的时候,都提示找不到pythonping模块,请教怎么解决,多谢!

为什么第三方模块被安装在Python38与虚拟环境两个地方? 能不能统一安装在一个路径并且能在vscode里面调试、打包?

多谢!多谢!!多谢!!!

智涅 发表于 2023-2-27 15:27:23

打包时试试pyinstaller 后面加命令
pyinstaller -w .\main.py --paths="D:\Program Files\Python38\Lib\site-packages"

智涅 发表于 2023-2-27 15:28:43

路径应该要到具体那个包吧,我之前试过串口的包打不进去,要增加路径--paths="E:\Python\Lib\site-packages\serial"
pyinstaller -w .\main.py --paths="E:\Python\Lib\site-packages\cv2"--paths="E:\Python\Lib\site-packages\serial"

Arm2048 发表于 2023-2-28 12:08:44

多谢2楼、3楼;
以前也打包过,没啥问题,这次各种问题{:cry:}

我把.py文件重新拷贝到一个新目录,之前是在原来的py上面修改的,还是原来的py运行调试环境;
把文件开头的一大串from import重新排序;没用的import也保留了;
在电脑的高级环境变量path中添加了虚拟环境site-packages的路径;
一番折腾,总算没出错,打包好了; 到现在也没明白到底什么原因找不到模块;
pyinstaller在python38目录下有一套,在虚拟环境路径下也有一套;
以下是vscode下的打包log,看样子还是用的python38目录的模块, 我觉得可能是之前的编译调试目录不纯净。

Arm2048 发表于 2023-2-28 12:16:57

请问:论坛不让上传自己电脑上图片吗?

Arm2048 发表于 2023-2-28 12:18:05

22178 INFO: Processing pre-find module path hook site from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
22194 INFO: site: retargeting to fake-dir 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\fake-modules'
22849 INFO: Processing module hooks...
22850 INFO: Loading module hook 'hook-difflib.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
22883 INFO: Loading module hook 'hook-distutils.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
22887 INFO: Loading module hook 'hook-distutils.util.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
22902 INFO: Loading module hook 'hook-encodings.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
23220 INFO: Loading module hook 'hook-heapq.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
23249 INFO: Loading module hook 'hook-lib2to3.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
23616 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
23620 INFO: Loading module hook 'hook-pickle.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
23623 INFO: Loading module hook 'hook-sysconfig.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
23625 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
23627 INFO: Loading module hook 'hook-xml.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
23852 INFO: Loading module hook 'hook-_tkinter.py' from 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks'...
24596 INFO: checking Tree
24780 INFO: checking Tree
25064 INFO: checking Tree
25204 INFO: Looking for ctypes DLLs
25529 WARNING: Ignoring /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation imported from d:\program files\python38\lib\site-packages\serial\tools\list_ports_osx.py - ctypes imports are only supported using bare filenames
25529 WARNING: Ignoring /System/Library/Frameworks/IOKit.framework/IOKit imported from d:\program files\python38\lib\site-packages\serial\tools\list_ports_osx.py - ctypes imports are only supported using bare filenames
25534 INFO: Analyzing run-time hooks ...
25541 INFO: Including run-time hook 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
25599 INFO: Including run-time hook 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
25662 INFO: Including run-time hook 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
25677 INFO: Including run-time hook 'd:\\program files\\python38\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
25716 INFO: Looking for dynamic libraries
26871 INFO: Looking for eggs
26872 INFO: Using Python library d:\program files\python38\python38.dll
页: [1]
查看完整版本: 请教python第三方包安装路径与打包问题