I am trying to use the pipreqs package to generate a requirements.txt file. Following the documentation's examples I have been unable to make it work.
It seems simple enough, the documentation tells me to use this command in the terminal:
$ pipreqs /home/project/location
In my case, this is the location of my project:
$ pipreqs /Users/ep9k/Desktop/UVA\ Big\Deal
And I get this error message:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/ep9k/Desktop/UVA BigDeal/requirements.txt'
The error message is correct, there is no requirements.txt file in that directory. I am trying to use pipreqs to create the requirements.txt file.
Reading the documentation, pipreqs is supposed to scan a python file for import statements and build the requirements.txt document based on that. So I tried this as well, with the file I want pipreqs to scan:
$ pipreqs /Users/ep9k/Desktop/UVA\ Big\Deal/1FigrFunctions.py
and I received this error, which is pretty much the same as above:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/ep9k/Desktop/UVA BigDeal/1FigrFunctions.py/requirements.txt'
I am sure the solution is obvious. What am I doing wrong?
Usage: Usage of the pipreqs is very easy. You just need to provide the root location of your project and the pipreqs automatically generate a requirements. txt file in root folder.
Simply open a terminal and navigate to the folder you want your requirements file to be in. You can then activate a virtual environment using venv or conda. It will take every package you have installed on that environment.
With your chosen environment selected using the Python: Select Interpreter command, run the Terminal: Create New Terminal command (Ctrl+Shift+`)) to open a terminal with that environment activated. In the terminal, run pip freeze > requirements. txt to create the requirements. txt file in your project folder.
I discovered how to solve this error using below steps- If you want to specify full path for your python file, use this -
pipreqs --encoding utf-8 "C:\Users\username\Downloads\Bl_container\training\fold\"
Also, the python file should be alone in the folder.
If you are currently in your python file directory, use this -
pipreqs --encoding utf-8 "./"
Using encoding to get rid of the map error. Make sure that you are not connected to any VPN or you may get HTTPConnection error.
I answered my own question. I think the errors were due to there being a bunch of files in the directory I was trying to run pipreqs on. To solve this problem, I created a new empty directory called "test" and put the file I wanted to generate requirements.txt for in that directory. So there is only one file in my new "test" directory. Then I ran the command as follows:
$ pipreqs /Users/ep9k/Desktop/test
and it worked. Really simple...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With