Since I got this error when building project in Xcode,
ModuleNotFoundError: No module named 'requests'
and then I’m trying to install the requests module with git command.
python toolchain.py pip install requests
However, I read the logs and I got this FileNotFoundError message. How can I deal with the error?
[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'
So I looked the file "/Users//Desktop/kivy/kivy-ios/dist/hostpython3/bin/pip3" and the virtual environment file "/Users//Desktop/kivy/kivy-ios//lib/python3.9/site-packages/sh.py" to see whether they are existed. And both of them are really existed! I’m so confuse with this error. So please help me out here! It is the finally step for me to run my first app soon! Thanks!
2
Answers
I have tried many ways to solve the issue in the last few days but failed. Finally, an admin in the kivy discord helps me solve the issue.
In my case, maybe I used the command
sudo toolchain.py build python kivy
. However, sudo is bad, and maybe what caused this issue.After I clean up the build and reinstall all kivy using
toolchain.py build python kivy
, I finally solve the issue. Thank you for the help from the admin and kivy community!Let’s tackle this in steps:
I’m making the assumption that your
toolchain.py
file is the script you would like to run, for which you need therequests
module.Step 1: Activate your virtual environment (you have possibly already done this)
Before installing a new module using
pip install <module>
, you want to activate your virtual environment, because you want to install it in there.You can do this by doing:
source <your-venv-path>/bin/activate
<your-venv-path>Scriptsactivate.bat
Some good answers on how to activate a virtual environment can be found for Windows and for Linux.
Step 2: Install the requests module
Now your virtual environment is active, you should be able to install the requests module like this:
pip install requests
Step 3: Run your script
After this, you should be able to run your script with the requests module installed like so:
python toolchain.py