I am trying to install a python software using the requirements file.
>> cat requirements.txt
Cython==0.15.1
numpy==1.6.1
distribute==0.6.24
logilab-astng==0.23.1logilab-common==0.57.1
netaddr==0.7.6
numexpr==2.0.1
ply==2.5
pycallgraph==0.5.1
pyflowtools==0.3.4.1
pylint==0.25.1
tables==2.3.1
wsgiref==0.1.2
So I create a virtual environment
>> mkvirtualenv parser
(parser)
>> pip freeze
distribute==0.6.24
wsgiref==0.1.2
(parser)
>> pip install -r requirements.txt
… and then I packages downloaded but not installed with errors: http://pastie.org/4079800
(parser)
>> pip freeze
distribute==0.6.24
wsgiref==0.1.2
Surprisingly, if I try to manually install each package, they install just fine.
For instance:
>> pip install numpy==1.6.1
(parser)
>> pip freeze
distribute==0.6.24
wsgiref==0.1.2
numpy==1.6.1
I am lost. What is going on?
PS: I am using pip
v1.1 and python
v2.7.2 with virtualenv
and virtualenvwrapper
asked Jun 13, 2012 at 13:17
Vaibhav BajpaiVaibhav Bajpai
16.2k13 gold badges52 silver badges84 bronze badges
1
It looks like the numexpr
package has an install-time dependency on numpy. Pip makes two passes through your requirements: first it downloads all packages and runs each one’s setup.py
to get its metadata, and then it installs them all in a second pass.
So, numexpr is trying to import from numpy in its setup.py, but when pip first runs numexpr’s setup.py, it has not yet installed numpy.
This is also why you don’t see this error when you install the packages one by one: if you install them one at a time, numpy will be fully installed in your environment before you pip install
numexpr.
The only solution is to install pip install numpy
before you ever run pip install -r requirements.txt
— you won’t be able to do this in a single command with a single requirements.txt file.
More info here: https://github.com/pypa/pip/issues/25
answered Jun 13, 2012 at 13:29
4
I come across with a similar issue and I ended up with the below:
cat requirements.txt | sed -e '/^s*#.*$/d' -e '/^s*$/d' | xargs -n 1 python -m pip install
That will read line by line the requirements.txt and execute pip. I cannot find from where I got the answer properly, so apologies for that, but I found some justification below:
- How sed works: https://howto.lintel.in/truncate-empty-lines-using-sed/
- Another similar answer but with git: https://stackoverflow.com/a/46494462/7127519
Hope this help with alternatives.
answered Aug 22, 2020 at 9:08
This is quite annoying sometimes, a bug of pip.
When you run pip install package_name the pip will first run pip check to the target package, and install all the required package for the dependency(target package).
But when you run pip install -r requirements.txt pip will try to directly install all the required packages listed one by one from top to bottom. Sometimes the dependency is listed above the package it depend upon.
The solution is simple:
1.pip install package_name
2.simply put the error package to the bottom of the requirements.txt
3.sometimes a particular version of the package is not be able to be installed,just install the newest version of it and update the data in requirements.txt
answered Dec 24, 2021 at 1:14
(myenv1) root@p-VirtualBox:~/online-exam/onlineexam# pip install requirements.txt
Collecting requirements.txt
Exception:
Traceback (most recent call last):
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/commands/install.py", line 353, in run
wb.build(autobuilding=True)
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/req/req_set.py", line 554, in _prepare_file
require_hashes
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/req/req_install.py", line 278, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/index.py", line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/index.py", line 423, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/index.py", line 568, in _get_pages
page = self._get_page(location)
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/index.py", line 683, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "/root/online-exam/myenv1/lib/python3.6/site-packages/pip/index.py", line 795, in get_page
resp.raise_for_status()
File "/root/online-exam/myenv1/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://pypi.org/simple/requirements-txt/
I have the following requirements.txt
file:
appdirs==1.4.3
decorator==4.3.0
numpy==1.15.4
pybind11==2.2.4
pyopencl==2018.2.2
pytools==2018.5.2
six==1.12.0
Running pip install -r requirements.txt
fails with:
Collecting appdirs==1.4.3 (from -r reqs.txt (line 1))
Downloading https://files.pythonhosted.org/packages/56/eb/810e700ed1349edde4cbdc1b2a21e28cdf115f9faf263f6bbf8447c1abf3/appdirs-1.4.3-py2.py3-none-any.whl
Collecting decorator==4.3.0 (from -r reqs.txt (line 2))
Downloading https://files.pythonhosted.org/packages/bc/bb/a24838832ba35baf52f32ab1a49b906b5f82fb7c76b2f6a7e35e140bac30/decorator-4.3.0-py2.py3-none-any.whl
Collecting numpy==1.15.4 (from -r reqs.txt (line 3))
Downloading https://files.pythonhosted.org/packages/86/04/bd774106ae0ae1ada68c67efe89f1a16b2aa373cc2db15d974002a9f136d/numpy-1.15.4-cp35-cp35m-manylinux1_x86_64.whl (13.8MB)
100% |████████████████████████████████| 13.8MB 1.2MB/s
Collecting pybind11==2.2.4 (from -r reqs.txt (line 4))
Downloading https://files.pythonhosted.org/packages/f2/7c/e71995e59e108799800cb0fce6c4b4927914d7eada0723dd20bae3b51786/pybind11-2.2.4-py2.py3-none-any.whl (145kB)
100% |████████████████████████████████| 153kB 1.2MB/s
Collecting pyopencl==2018.2.2 (from -r reqs.txt (line 5))
Downloading https://files.pythonhosted.org/packages/bc/58/3ab1246e94986f1b6953e76d7ea7e69d2dbfef7b3f3874eded48524a024f/pyopencl-2018.2.2.tar.gz (341kB)
100% |████████████████████████████████| 348kB 1.1MB/s
Complete output from command python setup.py egg_info:
---------------------------------------------------------------------------
Pybind11 is not installed.
---------------------------------------------------------------------------
Very likely, the build process after this message will fail.
Simply press Ctrl+C and type
python -m pip install pybind11
to fix this. If you don't, the build will continue
in a few seconds.
[1] https://pybind11.readthedocs.io/en/stable/
---------------------------------------------------------------------------
Continuing in 1 seconds...
---------------------------------------------------------------------------
Mako is not installed.
---------------------------------------------------------------------------
That is not a problem, as most of PyOpenCL will be just fine
without it. Some higher-level parts of pyopencl (such as
pyopencl.reduction) will not function without the templating engine
Mako [1] being installed. If you would like this functionality to
work, you might want to install Mako after you finish
installing PyOpenCL.
Simply type
python -m pip install mako
either now or after the installation completes to fix this.
[1] http://www.makotemplates.org/
---------------------------------------------------------------------------
Hit Ctrl-C now if you'd like to think about the situation.
---------------------------------------------------------------------------
Continuing in 1 seconds...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-d25rz2_5/pyopencl/setup.py", line 353, in <module>
main()
File "/tmp/pip-install-d25rz2_5/pyopencl/setup.py", line 320, in main
language='c++',
File "/tmp/pip-install-d25rz2_5/pyopencl/aksetup_helper.py", line 41, in __init__
self._include_dirs = self.include_dirs
File "/tmp/pip-install-d25rz2_5/pyopencl/aksetup_helper.py", line 55, in get_include_dirs
return self._include_dirs + self.get_additional_include_dirs()
File "/tmp/pip-install-d25rz2_5/pyopencl/aksetup_helper.py", line 52, in get_additional_include_dirs
return [self.get_numpy_incpath()]
File "/tmp/pip-install-d25rz2_5/pyopencl/aksetup_helper.py", line 47, in get_numpy_incpath
file, pathname, descr = find_module("numpy")
File "/home/app/.venv/lib/python3.5/imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'numpy'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-d25rz2_5/pyopencl/
Whereas running:
pip install numpy==1.15.4
pip install pybind11==2.2.4
pip install pyopencl==2018.2.2
works like a charm. Any idea why?
Thanks in advance.
——— EDIT: ———
I have also tried with pip-tools
without success… In this case I created a file requirements.in
:
numpy
pybind11
pyopencl
And ran pip-compile
, which fails with:
Traceback (most recent call last):
File "/home/app/.venv/bin/pip-compile", line 11, in <module>
sys.exit(cli())
File "/home/app/.venv/lib/python3.5/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/app/.venv/lib/python3.5/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/app/.venv/lib/python3.5/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/app/.venv/lib/python3.5/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/app/.venv/lib/python3.5/site-packages/piptools/scripts/compile.py", line 196, in cli
results = resolver.resolve(max_rounds=max_rounds)
File "/home/app/.venv/lib/python3.5/site-packages/piptools/resolver.py", line 101, in resolve
has_changed, best_matches = self._resolve_one_round()
File "/home/app/.venv/lib/python3.5/site-packages/piptools/resolver.py", line 198, in _resolve_one_round
for dep in self._iter_dependencies(best_match):
File "/home/app/.venv/lib/python3.5/site-packages/piptools/resolver.py", line 284, in _iter_dependencies
dependencies = self.repository.get_dependencies(ireq)
File "/home/app/.venv/lib/python3.5/site-packages/piptools/repositories/pypi.py", line 217, in get_dependencies
self._dependencies_cache[ireq] = self.resolve_reqs(download_dir, ireq, wheel_cache)
File "/home/app/.venv/lib/python3.5/site-packages/piptools/repositories/pypi.py", line 183, in resolve_reqs
results = resolver._resolve_one(reqset, ireq)
File "/home/app/.venv/lib/python3.5/site-packages/pip/_internal/resolve.py", line 256, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/home/app/.venv/lib/python3.5/site-packages/pip/_internal/resolve.py", line 209, in _get_abstract_dist_for
self.require_hashes
File "/home/app/.venv/lib/python3.5/site-packages/pip/_internal/operations/prepare.py", line 298, in prepare_linked_requirement
abstract_dist.prep_for_dist(finder, self.build_isolation)
File "/home/app/.venv/lib/python3.5/site-packages/pip/_internal/operations/prepare.py", line 126, in prep_for_dist
self.req.run_egg_info()
File "/home/app/.venv/lib/python3.5/site-packages/pip/_internal/req/req_install.py", line 473, in run_egg_info
command_desc='python setup.py egg_info')
File "/home/app/.venv/lib/python3.5/site-packages/pip/_internal/utils/misc.py", line 705, in call_subprocess
% (command_desc, proc.returncode, cwd))
pip._internal.exceptions.InstallationError: Command "python setup.py egg_info" failed with error code 1 in /tmp/tmp0ykgmwk4build/pyopencl/
Like any programming language, an error in python occurs when a given code fails to follow the syntax rules. When a code does not follow the syntax, python cannot recognize that segment of code, so it throws an error. Errors can be of different types, such as runtime error, syntax error, logical error, etc. IOError errno 2 no such file or directory is one such type of error. Let us first understand each individual term of the error.
Note : Starting from Python 3.3, IOError is an aliases of OSError
What is IOError?
An IOError is thrown when an input-output operation fails in the program. The common input-output operations are opening a file or a directory, executing a print statement, etc. IOError is inherited from the EnvironmentError. The syntax of IOError is:
IOError : [Error number] ‘Reason why the error occurred’: ‘name of the file because of which the error occurred’
Examples of IOError are :
- Unable to execute the open() statement because either the filename is incorrect or the file is not present in the specified location.
- Unable to execute the print() statements because either the disk is full or the file cannot be found
- The permission to access the particular file is not given.
What is errno2 no such file or directory?
The ‘errorno 2 no such file or directory‘ is thrown when you are trying to access a file that is not present in the particular file path or its name has been changed.
This error is raised either by ‘FileNotFoundError’ or by ‘IOError’. The ‘FileNotFoundError’ raises ‘errorno 2 no such file or directory‘ when using the os library to read a given file or a directory, and that operation fails.
The ‘IOError’ raises ‘errorno 2 no such file or directory‘ when trying to access a file that does not exist in the given location using the open() function.
Handling ‘IOError [errorno 2] no such file or directory’
‘IOError errorno 2 no such file or directory‘ occurs mainly while we are handling the open() function for opening a file. Therefore, we will look at several solutions to solve the above error.
We will check if a file exists, raise exceptions, solve the error occurring while installing ‘requirements.txt,’ etc.
Checking if the file exists beforehand
If a file or a directory does not exist, it will show ‘IOError [errorno 2] no such file or directory’ while opening it. Let us take an example of opening a file named ‘filename.txt’.
The given file does not exist and we shall see what happens if we try to execute it.
Since the above text file does not exist, it will throw the IOError.
Traceback (most recent call last): File "main.py", line 1, in <module> f = open('filename.txt') IOError: [Errno 2] No such file or directory: 'filename.txt'
To avoid the above error from being thrown, we will use several methods which will first check if the file exists or not. It will execute the open() function only if the file exists.
We have two modules containing functions for checking if a file exists.
- OS Module
- Pathlib Module
Using the OS Module
In the os module, there are three functions which can be used:
- os.path.isfile()
- os.path.isdir()
- os.path.exists()
To solve the IOError, we can use either of the above function in a condition statement. We will pass the pathname of the file as an argument to the above functions.
If the file or the directory exists, the function shall return True else False. Bypassing either of the above functions as the conditional statement ensures that python will open a file only if it exists, thus preventing an error from occurring.
We will use os.path.isfile() when we want to check if a file exists or not, os.path.isdir() to check if a directory exists or not and os.path.exists() to check if a path exists or not.
Since we want to check for a file, we can use either the os.path.isfile() function or os.path.exists() function. We shall apply the function to the above example.
import os path_name = "filename.txt" if os.path.isfile(path_name): print("File exists") f = open(path_name) #Execute other file operations here f.close() else: print("File does not exist! IOError has occured")
First, we have imported the os module. Then we have a variable named ‘path_name‘ which stores the path for the file.
We passed the path_name as an argument to the os.path.isfile() function. If the os.path.isfile() function returns a true value. Then it will print “File exists” and execute the other file operations.
If the file does not exist, then it will print the second statement in the else condition. Unlike the previous case, here, it will not throw an error and print the message.
File does not exist! IOError has occured
Similarly, we can also use os.path.exists() function.
Using the pathlib module
The pathlib module contains three functions – pathlib.Path.exists(), pathlib.Path.is_dir() and pathlib.Path.is_file().
We will use pathlib.Path.is_file() in this example. Just like the os module, we will use the function in an if conditional statement.
It will execute the open() function only if the file exists. Thus it will not throw an error.
from pathlib import Path path_name = "filename.txt" p = Path(path_name) if p.is_file(): print("File exists") f = open(path_name) #Execute other file operations here f.close() else: print("File does not exist! IOError has occured")
Since the file does not exist, the output is :
File does not exist! IOError has occured
Using try – except block
We can also use exception handling for avoiding ‘IOError Errno 2 No Such File Or Directory’. In the try block, we will try to execute the open() function.
If the file is present, it will execute the open() function and all the other file operations mentioned in the try block. But, if the file cannot be found, it will throw an IOError exception and execute the except block.
try: f = open("filename.txt") #Execute other operations f.close() except IOError as io: print(io)
Here, it will execute the except block because ‘filename.txt’ does not exist. Instead of throwing an error, it will print the IOError.
[Errno 2] No such file or directory: 'filename.txt'
We can also print a user defined message in the except block.
try: f = open("filename.txt") #Execute other operations f.close() except IOError: print("File does not exist. IOError has occured")
The output will be:
File does not exist. IOError has occured
IOError errno 2 no such file or directory in requirements.txt
Requirements.txt is a file containing all the dependencies in a project and their version details.
Basically, it contains the details of all the packages in python needed to run the project. We use the pip install command to install the requirements.txt file. But it shows the ‘IOError errno 2 no such file or directory’ error.
!pip install -r requirements.txt
The thrown error is:
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
To solve the above error, we use the pip freeze command. When we use pip freeze, the output will contain the package along with its version.
The output will be in a configuration that we will use with the pip install command.
pip freeze > requirements.txt
Now, we will try to execute the pip install command again. It will no longer throw errors and all the packages will be installed successfully.
Opening file in ‘w+’ mode
While trying to open a text file, the default mode will be read mode. In that case, it will throw the ‘IOError Errno 2 No Such File Or Directory’ error.
f = open("filename.txt") f.close() print("Successful")
The output is:
Traceback (most recent call last): File "main.py", line 1, in <module> f = open("filename.txt") IOError: [Errno 2] No such file or directory: 'filename.txt'
To solve the error, we can open the file in ‘w+’ mode. This will open the file in both – reading and writing mode. If the file does not exist, it will create a new file, and if the file exists, it will overwrite the contents of the file. This way, it will not throw an error.
f = open("filename.txt", 'w+') f.close() print("Successful")
The output is:
Successful
Apart from all the above methods, there are some ways to ensure that the IOError does not occur. You have to ensure that you are giving the absolute path as the path name and not simply the name of the file.
Also, see to that there are no escape sequences in the path name of this file.
For example : In path_name = "C:name.txt ", it will consider the 'n' from 'name.txt' as an escape sequence. So, it will not be able to find the file 'name.txt'.
Also, Read
- How to Solve “unhashable type: list” Error in Python
- How to solve Type error: a byte-like object is required not ‘str’
- Invalid literal for int() with base 10 | Error and Resolution
- How to Solve TypeError: ‘int’ object is not Subscriptable
What is the difference between FileNotFoundError and IOError
Both the errors occur when you are trying to access a file that is not present in the particular file path, or its name has been changed. The difference between the two is that FileNotFoundError is a type of OSError, whereas IOError is a type of Environment Error.
This sums up everything about IOError Errno 2 No Such File Or Directory. If you have any questions, do let us know in the comments below.
Until then, Keep Learning!
Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to installl python package and the command window is unable to find the requirements.txt in the location and I am facing following error IOError: [Errno 2] No such file or directory: ‘requirements.txt’ ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. in python. So Here I am Explain to you all the possible solutions here.
Without wasting your time, Let’s start This Article to Solve This Error.
Contents
- How IOError: [Errno 2] No such file or directory: ‘requirements.txt’ Error Occurs ?
- How To Solve IOError: [Errno 2] No such file or directory: ‘requirements.txt’ Error ?
- Solution 1: create the requirements file first
- Solution 2: find requirements.txt path
- Summary
I am trying to installl python package and the command window is unable to find the requirements.txt in the location and I am facing following error.
IOError: [Errno 2] No such file or directory: 'requirements.txt'
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
How To Solve IOError: [Errno 2] No such file or directory: ‘requirements.txt’ Error ?
- How To Solve IOError: [Errno 2] No such file or directory: ‘requirements.txt’ Error ?
To Solve IOError: [Errno 2] No such file or directory: ‘requirements.txt’ Error Here if you are using virtual environment then you need to create the requirements file first then you can install packages. To create the requirements file just use this command and it will create requirements file for you pip freeze > requirements.txt. Second solution is Just find requirements.txt path and then try to install.
- IOError: [Errno 2] No such file or directory: ‘requirements.txt’
To Solve IOError: [Errno 2] No such file or directory: ‘requirements.txt’ Error Here if you are using virtual environment then you need to create the requirements file first then you can install packages. To create the requirements file just use this command and it will create requirements file for you pip freeze > requirements.txt. Second solution is Just find requirements.txt path and then try to install.
Solution 1: create the requirements file first
Here if you are using virtual environment then you need to create the requirements file first then you can install packages. To create the requirements file just use this command and it will create requirements file for you.
pip freeze > requirements.txt
Solution 2: find requirements.txt path
Just find requirements.txt path and then try to install. Just use this command to find path.
find -name "requirements.txt"
OR
find . -regex '.*requirements.txt$' //on theroot directory of your terminal
and then run this command.
pip install -r requirements.txt
Summary
It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also, Read
- TypeError: load() missing 1 required positional argument: ‘Loader’