'pip install -r requirements.txt [Errno 2] No such file or directory: 'requirements.txt'
I am setting up the base for a django project, I have cloned a repo and I have just created a virtual environment for the project in the same directory.
But when I try to run the command pip install -r requirements.txt in the project directory I get this error:
[Errno 2] No such file or directory: 'requirements.txt'
I believe I'm just running it in the wrong directory, but I don't really know where I should run it. Do you have any idea where the file could be located?
Solution 1:[1]
If you are using a virtual environment just use the following line.
pip freeze > requirements.txt
It commands to create the requirements file first.
Or in dockerfile, RUN pip freeze > requirements.txt .
Solution 2:[2]
If you are facing this issue while using a docker or flowing getting started guide from docker site then you need to update your Docker file.
just add following line to create the requirements.txt file before the line "RUN pip install --no-cache-dir -r requirements.txt" in your Dockerfile
RUN pip freeze > requirements.txt
Solution 3:[3]
A better way of doing this is write this on the root directory of your terminal:
find . -regex '.*requirements.txt$'
It will search in your root directory and all subfolders for a file called requirements.txt. After the command response, you can get the directory and run the pip install -r requirements.txt on it.
Solution 4:[4]
Try using this in your terminal then go to the directory and use the pip install command.
find -name "requirements.txt"
Solution 5:[5]
I tried this and solved:
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt
Solution 6:[6]
Check if you have requirements.txt file in the directory.
and then run the following command.pip install -r requirements.txt
Solution 7:[7]
Make sure the requirements.txt file is in the same folder where you are installing it using pip install -r requirements.txt
Solution 8:[8]
I had this problem, 3 years too late however move the req file into downloads and then try it again
Solution 9:[9]
Well, I got the same kind of error cmd code image and this is how I resolved it.
pip freeze > requirements.txt
If you see an error it is because I named my text document as 'requirements.txt' and not 'requirements', the .txt addition will be done by Windows itself we don't need to bother about that.
notice the difference between two different txt file with the same name 'requirements'
Finally, implement your code:
pip install -r requirements.txt
see the code is not showing an error now
Solution 10:[10]
I faced the same issue and this is because I wrote the RUN instruction before COPY instruction, so make sure to write it in the correct order.
FROM python:3
WORKDIR /usr/src/app
RUN pip install -r requirements.txt
COPY . .
CMD [ "python", "./test.py" ]
The solution:
FROM python:3
WORKDIR /usr/src/app
COPY . .
RUN pip install -r requirements.txt
CMD [ "python", "./test.py" ]
Solution 11:[11]
if you are on Mac os
pip3 freeze > requirements.txt
and then
pip3 install -r requirements.txt
Solution 12:[12]
I solved this problem by indicating the full path to file (for example):
pip install -r /Users/aleks/Desktop/....../requirements.txt
Solution 13:[13]
Please check the command which you are running, I faced the same issue and after few minutes of search, I found I am placing a space in between mysql -connector.
Correct command:
pip3 install mysql-connector
Wrong command:
pip3 install mysql -connector
Solution 14:[14]
I had the same problem and change my directory as follow:
import os
os.chdir('Your Path (GitHub project, ...)')
!pip install -r requirements.txt
instead of
cd path
pip install -r requirements.txt
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
