Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python main.py --platform xhs --lt qrcode --type search 命令行执行时缺少库 import httpx ModuleNotFoundError: No module named 'httpx' #518

Open
dannishushu opened this issue Dec 9, 2024 · 4 comments

Comments

@dannishushu
Copy link

dannishushu commented Dec 9, 2024

按照顺序执行,都没有问题,python版本是3.9.6

 cd MediaCrawler

 python -m venv venv
 
 source venv/bin/activate


 pip install -r requirements.txt


 playwright install
 

 python main.py --platform xhs --lt qrcode --type search

出现问题如下:

(venv) x@MacBook-Air PythonProject % python main.py --platform xhs --lt qrcode --type search
Traceback (most recent call last):
File "/Users/x/PycharmProjects/PythonProject/main.py", line 4, in
import cmd_arg
File "/Users/x/PycharmProjects/PythonProject/cmd_arg/init.py", line 3, in
from .arg import *
File "/Users/x/PycharmProjects/PythonProject/cmd_arg/arg.py", line 7, in
from tools.utils import str2bool
File "/Users/x/PycharmProjects/PythonProject/tools/utils.py", line 4, in
from .crawler_util import *
File "/Users/x/PycharmProjects/PythonProject/tools/crawler_util.py", line 11, in
import httpx
ModuleNotFoundError: No module named 'httpx'

在pycharm里debug模式没有问题,但命令行执行时python main.py 就会报错缺少httpx,可是httpx已经安装了,并且版本确实是0.24.0

@NanmiCoder
Copy link
Owner

这种问题请自查,不属于MediaCrawler仓库问题范畴。

@dannishushu
Copy link
Author

dannishushu commented Dec 10, 2024

这种问题请自查,不属于MediaCrawler仓库问题范畴。

非常不好意思

venv中从pip list来看是有http 0.24.0这个包的

又尝试单独安装 pip install httpx==0.24.0

Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting httpx==0.24.0
Using cached https://mirrors.aliyun.com/pypi/packages/4e/c1/692013f1e6115a061a14f6c7d05947515a1eb7b85ef6e9bf0ffbf0e92738/httpx-0.24.0-py3-none-any.whl (75 kB)
Requirement already satisfied: sniffio in ./venv/lib/python3.9/site-packages (from httpx==0.24.0) (1.3.1)
Requirement already satisfied: idna in ./venv/lib/python3.9/site-packages (from httpx==0.24.0) (3.10)
Collecting httpcore<0.18.0,>=0.15.0
Using cached https://mirrors.aliyun.com/pypi/packages/94/2c/2bde7ff8dd2064395555220cbf7cba79991172bf5315a07eb3ac7688d9f1/httpcore-0.17.3-py3-none-any.whl (74 kB)
Requirement already satisfied: certifi in ./venv/lib/python3.9/site-packages (from httpx==0.24.0) (2024.8.30)
Requirement already satisfied: h11<0.15,>=0.13 in ./venv/lib/python3.9/site-packages (from httpcore<0.18.0,>=0.15.0->httpx==0.24.0) (0.14.0)
Requirement already satisfied: anyio<5.0,>=3.0 in ./venv/lib/python3.9/site-packages (from httpcore<0.18.0,>=0.15.0->httpx==0.24.0) (4.7.0)
Requirement already satisfied: exceptiongroup>=1.0.2 in ./venv/lib/python3.9/site-packages (from anyio<5.0,>=3.0->httpcore<0.18.0,>=0.15.0->httpx==0.24.0) (1.2.2)
Requirement already satisfied: typing_extensions>=4.5 in ./venv/lib/python3.9/site-packages (from anyio<5.0,>=3.0->httpcore<0.18.0,>=0.15.0->httpx==0.24.0) (4.12.2)
Installing collected packages: httpcore, httpx
Attempting uninstall: httpcore
Found existing installation: httpcore 1.0.7
Uninstalling httpcore-1.0.7:
Successfully uninstalled httpcore-1.0.7
Successfully installed httpcore-0.17.3 httpx-0.24.0

可以看到也确实是安装在venv下的

把项目clone下来之后严格按照Readme的步骤执行的命令,运行不起来,可能会有人和我有一样的问题,我的意思如果能找到原因后续可以优化在Readme中

@NanmiCoder
Copy link
Owner

这个和仓库没有什么关系的,是你的mac系统python环境问题,你的虚拟环境虽然装了httpx且看起来进了虚拟环境,但是实际的运行的python不是你的虚拟环境的,临时解决方案:直接全局install,然后你要去谷歌搜索下你这个问题的解决方案。

@dannishushu
Copy link
Author

这个和仓库没有什么关系的,是你的mac系统python环境问题,你的虚拟环境虽然装了httpx且看起来进了虚拟环境,但是实际的运行的python不是你的虚拟环境的,临时解决方案:直接全局install,然后你要去谷歌搜索下你这个问题的解决方案。

多谢作者的认真负责

执行命令改为 ./venv/bin/python3.9 main.py --platform xhs --lt qrcode --type search 就没问题了

很奇怪,ls -l ./venv/bin/python3.9 显示python的位置在/Users/x/.pyenv/versions/3.9.6/bin/python3.9
系统环境变量明明也配置了alias, python -V 和 which python都显示就是用的/Users/x/.pyenv/versions/3.9.6/bin/python3.9

但如果不用./venv/bin/python3.9执行,确实是“实际的运行的python不是你的虚拟环境的”,奇怪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants