[Django]-Pip install -r requirements.txt [Errno 2] No such file or directory: 'requirements.txt'

31👍

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

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

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.

4👍

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

find -name "requirements.txt"

4👍

I tried this and solved:

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

2👍

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👍

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

👤Ishu

1👍

if you are on Mac os

 pip3 freeze > requirements.txt

and then

pip3 install -r requirements.txt

1👍

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

pip install -r /Users/aleks/Desktop/....../requirements.txt

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

0👍

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

0👍

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

👤Minty

0👍

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

👤randon

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

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.

0👍

Make sure you write correctly requirements.txt because I had the same problem and ran the command:

pip install -r requirments.txt

instead of

pip install -r requirements.txt

-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

-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

-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

Leave a comment