39

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?

Rohan Devaki
  • 2,931
  • 1
  • 14
  • 22
siama
  • 549
  • 1
  • 4
  • 6
  • 1
    You should run it where `requirements.txt` is –  Oct 20 '17 at 17:38
  • As I'm pretty new to this, I have no idea where to find it. But now I know it might be in the root of a repo, so thank you! I have found the file and cd to the right directory, but it's still giving me the same error. – siama Oct 20 '17 at 17:44
  • I managed to do it, but now I have a different error: " Could not find a version that satisfies the requirement pkg-resources==0.0.0 (from -r requirements.txt (line 2)) (from versions: ) No matching distribution found for pkg-resources==0.0.0 (from -r requirements.txt (line 2)) " How do I install the package? – siama Oct 20 '17 at 17:52

18 Answers18

29

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 .

Abhi
  • 2,115
  • 2
  • 18
  • 29
13

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
Qasim Nadeem
  • 597
  • 4
  • 17
9

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.

hermancaldara
  • 451
  • 1
  • 6
  • 13
  • Thank you! I managed to do it, but now I have a different error: " Could not find a version that satisfies the requirement pkg-resources==0.0.0 (from -r requirements.txt (line 2)) (from versions: ) No matching distribution found for pkg-resources==0.0.0 (from -r requirements.txt (line 2)) " Do you know how to install the package? – siama Oct 20 '17 at 21:36
  • It seems like a bug. I found an answer here: https://stackoverflow.com/questions/39577984/what-is-pkg-resources-0-0-0-in-output-of-pip-freeze-command. I think you can open the `requirements.txt` file and remove the line that has this package (if there is this line). – hermancaldara Oct 21 '17 at 00:36
  • I tried but it doesn't let me, maybe because I'm a new user! Sorry about that! – siama Oct 22 '17 at 20:23
4

Try using this in your terminal then go to the directory and use the pip install command.

find -name "requirements.txt"
pissall
  • 7,109
  • 2
  • 25
  • 45
3

I tried this and solved:

COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt
1

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

Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60
Ishu
  • 31
  • 5
1

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" ]
1

if you are on Mac os

 pip3 freeze > requirements.txt

and then

pip3 install -r requirements.txt
Khem Raj Regmi
  • 2,130
  • 19
  • 21
1

I solved this problem by indicating the full path to file (for example):

pip install -r /Users/aleks/Desktop/....../requirements.txt
lemon
  • 14,875
  • 6
  • 18
  • 38
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 31 '22 at 12:28
  • This worked for me on a Mac OS Monterey on MacBook Pro. You can key in pip install -r and then drag the requirements.txt file and drop it in the terminal screen and it will point the absolute path, for some reason it worked. – Kandeep Sep 27 '22 at 03:40
1

Make sure you cd back into the repo file after creating your virtual environment to store project. In my case, I created, cd into the folder, then forgot to cd back into the repo file. I struggled with all the options of solutions I found here till I carefully looked at my commands and had to cd back. That way I install requirements.txt still using this:

pip install -r requirements.txt
MD Mushfirat Mohaimin
  • 1,966
  • 3
  • 10
  • 22
Chinasa
  • 11
  • 1
0

Check if you have requirements.txt file in the directory.
and then run the following command.
pip install -r requirements.txt

vishwaraj
  • 487
  • 5
  • 5
0

Make sure the requirements.txt file is in the same folder where you are installing it using pip install -r requirements.txt

Rohan Devaki
  • 2,931
  • 1
  • 14
  • 22
Minty
  • 1
  • 2
0

I had this problem, 3 years too late however move the req file into downloads and then try it again

randon
  • 1
  • 1
    Usually, the file `requirements.txt` is in the root of the repository, not in the Downloads directory – Benbb96 Jan 25 '21 at 11:40
0

it gives "pip install -r requirements.txt [Errno 2] No such file or directory: 'requirements.txt', " times and times, with the codes

  1. python –m venv env
  2. env\Scripts\activate
  3. pip install – r requirements.txt
    ... after the codes are below, I write. It runs.
  4. python –m venv xenv (with different env's name)
  5. env\Scripts\activate
  6. pip install – r requirements.txt
    ... it runs. the file names in the requirements.txt are underlined with red, but it runs and it accepts, opens the files, and app runs.
krsd
  • 1
0

Find requirements.txt using the command: find -name "requirements.txt"

Get into the directory then run: pip install -r requirements.txt

That worked for me.

-1

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
GooDeeJAY
  • 1,681
  • 2
  • 20
  • 27
lalit pant
  • 39
  • 3
-1

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
abbas abaei
  • 65
  • 3
  • 3
  • 8
  • Welcome to Stackoverflow. Isn't your solution specific to the use of iPython and Jupyter? I certain that you cannot use the `!pip install ...` call inside a normal python script or shell, as this is specific to ipython and Jupyter. – jhoepken Jun 08 '21 at 12:40
  • Of course, you're right. This solution works for Google Colab. – abbas abaei Mar 13 '22 at 12:27
-3

Try to run this one in your terminal it will automatically list all the dependencies you have.

NB:

it's recommended for flask development

pip freeze > requirements.txt
Lutaaya Huzaifah Idris
  • 3,596
  • 8
  • 38
  • 77