因为我在Xcode中构建项目时遇到了这个错误,
ModuleNotFoundError: No module named 'requests'
然后我尝试用git命令安装requests模块。
python toolchain.py pip install requests
但是,我阅读了日志,我得到了这个FileNotFoundError消息。我该如何处理这个错误呢?
[INFO ] Using the bundled version for recipe 'host_setuptools3'
[INFO ] Using the bundled version for recipe 'hostopenssl'
[INFO ] Using the bundled version for recipe 'hostpython3'
[INFO ] Global: hostpython located at /Users/<myname>/Desktop/kivy/kivy-ios/dist/hostpython3/bin/python
[INFO ] Global: hostpgen located at /Users/<myname>/Desktop/kivy/kivy-ios/dist/hostpython3/bin/pgen
[INFO ] Using the bundled version for recipe 'ios'
[INFO ] Using the bundled version for recipe 'kivy'
[INFO ] Using the bundled version for recipe 'libffi'
[INFO ] Include dir added: {arch.arch}/ffi
[INFO ] Using the bundled version for recipe 'openssl'
[INFO ] Include dir added: {arch.arch}/openssl
[INFO ] Using the bundled version for recipe 'pyobjus'
[INFO ] Using the bundled version for recipe 'python3'
[INFO ] Using the bundled version for recipe 'sdl2'
[INFO ] Include dir added: common/sdl2
[INFO ] Using the bundled version for recipe 'sdl2_image'
[INFO ] Include dir added: common/sdl2_image
[INFO ] Using the bundled version for recipe 'sdl2_mixer'
[INFO ] Include dir added: common/sdl2_mixer
[INFO ] Using the bundled version for recipe 'sdl2_ttf'
[INFO ] Include dir added: common/sdl2_ttf
[INFO ] Executing pip with: ['install', '--isolated', '--prefix', '/Users/<myname>/Desktop/kivy/kivy-ios/dist/root/python3', 'requests']
[INFO ] Running Shell: /Users/<myname>/Desktop/kivy/kivy-ios/dist/hostpython3/bin/pip3 ('install', '--isolated', '--prefix', '/Users/<myname>/Desktop/kivy/kivy-ios/dist/root/python3', 'requests') {'_env': {'CC': '/bin/false', 'CXX': '/bin/false', 'PYTHONPATH': '/Users/<myname>/Desktop/kivy/kivy-ios/dist/root/python3/lib/python3.9/site-packages', 'PYTHONOPTIMIZE': '2'}, '_iter': True, '_out_bufsize': 1, '_err_to_out': True}
Traceback (most recent call last):
File "/Users/<myname>/Desktop/kivy/kivy-ios/toolchain.py", line 3, in <module>
main()
File "/Users/<myname>/Desktop/kivy/kivy-ios/kivy_ios/toolchain.py", line 1555, in main
ToolchainCL()
File "/Users/<myname>/Desktop/kivy/kivy-ios/kivy_ios/toolchain.py", line 1299, in __init__
getattr(self, args.command)()
File "/Users/<myname>/Desktop/kivy/kivy-ios/kivy_ios/toolchain.py", line 1514, in pip
_pip(sys.argv[2:])
File "/Users/<myname>/Desktop/kivy/kivy-ios/kivy_ios/toolchain.py", line 1186, in _pip
shprint(pip_cmd, *args, _env=pip_env)
File "/Users/<myname>/Desktop/kivy/kivy-ios/kivy_ios/toolchain.py", line 55, in shprint
cmd = command(*args, **kwargs)
File "/Users/<myname>/Desktop/kivy/kivy-ios/posEnv/lib/python3.9/site-packages/sh.py", line 1524, in __call__
return RunningCommand(cmd, call_args, stdin, stdout, stderr)
File "/Users/<myname>/Desktop/kivy/kivy-ios/posEnv/lib/python3.9/site-packages/sh.py", line 780, in __init__
self.process = OProc(self, self.log, cmd, stdin, stdout, stderr,
File "/Users/<myname>/Desktop/kivy/kivy-ios/posEnv/lib/python3.9/site-packages/sh.py", line 2125, in __init__
raise ForkException(fork_exc)
sh.ForkException:
Original exception:
===================
Traceback (most recent call last):
File "/Users/gordonkwok/Desktop/kivy/kivy-ios/<myenv>/lib/python3.9/site-packages/sh.py", line 2080, in __init__
os.execve(cmd[0], cmd, ca["env"])
FileNotFoundError: [Errno 2] No such file or directory: b'/Users/<myname>/Desktop/kivy/kivy-ios/dist/hostpython3/bin/pip3'
所以我查看了文件“/Users//Desktop/kivy/kivy-ios/dist/hostpython 3/bin/pip 3”和虚拟环境文件“/Users//Desktop/kivy/kivy-ios//lib/python3.9/site-packages/sh.py“,看看它们是否存在。它们都是真的存在!我对这个错误感到很困惑。所以请帮助我解决这个问题!这是我运行第一个应用程序的最后一步!谢谢!
1条答案
按热度按时间hmmo2u0o1#
让我们分步骤来解决这个问题:
我假设您的
toolchain.py
文件是您要运行的脚本,为此您需要requests
模块。在使用
pip install <module>
安装新模块之前,您希望激活虚拟环境,因为您希望将其安装在那里。您可以通过执行以下操作来执行此操作:
source <your-venv-path>/bin/activate
<your-venv-path>\Scripts\activate.bat
有关如何激活虚拟环境的一些好答案,可以在Windows和Linux中找到。
现在您的虚拟环境处于活动状态,您应该能够安装requests模块,如下所示:
pip install requests
在此之后,您应该能够运行安装了requests模块的脚本,如下所示:
python toolchain.py