简体   繁体   中英

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?

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 .

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

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.

尝试在终端中使用它,然后转到目录并使用 pip install 命令。

find -name "requirements.txt"

I tried this and solved:

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

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

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

确保requirements.txt文件位于使用pip install -r requirements.txt安装它的同一文件夹中

我遇到了这个问题,已经晚了 3 年,但是将 req 文件移动到下载中,然后再试一次

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

if you are on Mac os

 pip3 freeze > requirements.txt

and then

pip3 install -r requirements.txt

我通过指示文件的完整路径解决了这个问题(例如):

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

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM