|  |      1masker      2022-10-19 14:26:11 +08:00 via Android pyinstaller -p  指向你的 site-packages 路径 | 
|      2fbichijing      2022-10-19 14:41:10 +08:00  1 因为没有代码,场景无法复现。 不过最近的 pyinstaller 似乎有些问题,我用最新版本的 pyinstaller 打包的时候也出现了一些莫名其妙的错误。由此我一般都将 pyinstaller 回退到以前的版本,4.9 还是 5.1 ,不知道最新版本有没有修好了。个人之见。 | 
|      3PEax OP @fbichijing  import requests res = requests.get('https://www.baidu.com', proxies={"http": "socks5://127.0.0.1:5500", "https": "socks5://127.0.0.1:5500"}) print(res.text) pyinstaller -F xxx.py 就是最简单的访问,就这几行代码 | 
|      4fbichijing      2022-10-19 18:37:01 +08:00 @PEax 我记得要使用 socks5 代理还要加个 h 。 python 3.8 pyinstaller 4.9 ```python import os import requests from lxml import etree url = 'https://google.com' proxies = {"http": "socks5h://127.0.0.1:1080", "https": "socks5h://127.0.0.1:1080"} res = requests.get(url, proxies=proxies) response = etree.HTML(res.text) print(response.xpath('//title/text()')) os.system('pause') ``` | 
|      5fbichijing      2022-10-19 18:40:52 +08:00 | 
|      6PEax OP @fbichijing 我发现是我 mac 用虚拟机打包的问题,我换成 win 就不会了,并且加上 h 就好了!,谢谢大佬 | 
|  |      7ysc3839      2022-10-19 20:19:36 +08:00 via Android | 
|      8fbichijing      2022-10-19 20:31:18 +08:00 @ysc3839 requests 需要。https://stackoverflow.com/questions/12601316/how-to-make-python-requests-work-via-socks-proxy#answer-15661226 评论里也有讨论。我仅记得当时我也遇到了什么报错,查找了很多网页,有看到过一个网页写了很详细的解释。时间过于久远,当时我也没有记笔记或者保存脱机页面的习惯。后来就只留下这里加一个 h 就不会报错的印象在脑海里......^_^ | 
|  |      9laqow      2022-10-19 21:47:36 +08:00 pyinstaller 打包在 import 时可能要具体到函数,用 form requests import get, res = get('https://www.baidu.com', proxies={"http": "socks5://127.0.0.1:5500", "https": "socks5://127.0.0.1:5500"}) 可能就行了 | 
|      10gablic      2022-10-20 09:35:16 +08:00 怀疑环境问题,试试指定 pyinstaller 和 site-packages 的目录 python "pyinstaller.exe 路径" --onefile --path "site-packages 路径" xxx.py | 
|      11ungrown      2022-10-20 11:32:11 +08:00 @fbichijing #8 也就是说其实不是“漏库”的原因,而是 scheme 相关的 trick | 
|      12rev1si0n      2022-10-20 15:30:18 +08:00 直接在入口脚本先 import socks import sockshandler 然后再打包 |