I am new in python. I am creating an API in python using flask-restful. I have created APIs in java.In java we have pom.xml file for dependencies...is there any for python and flask-restful
2 Answers
Yes. In python We generally make requirements.txt so anyone who wants to download all the requirements can simply run the command
pip install -r requirements.txt
so if you are using virtualenv you can simply do
pip freeze > requirements.txt
Otherwise you need to add all the dependencies manually & the requirements.txt file will looks like
decorator==4.3.0
defusedxml==0.5.0
entrypoints==0.2.3
Flask==1.0.2
google==2.0.1
Note: It's just for example.

- 303
- 3
- 12
-
for every dependency, I want to use, I have to write it down in this file .......but in a specific way right ???? where can I find that way ??? – creatorworld Jun 05 '20 at 06:53
-
I have already given the example. like you are using the Flask package & version 1.0.2 so it will be like Flask==1.0.2. Likewise, you need to add other packages one below other. – Rahul Agrawal Jun 05 '20 at 07:03
-
2@creatorworld `==` means "exactly this version", `>=` means "at least this version" and just the dependency itself means "doesn't matter." You can even specify a range. Check out [this post](https://stackoverflow.com/questions/5226311/installing-specific-package-versions-with-pip?rq=1). – Thomas Jun 05 '20 at 07:09
I would recommend using pipenv
.
In Java, you need to know where your library dependencies are located and they usually are downloaded once for each project as you need them. In other words, each project will have their own set of plugins. This is also the same for non-global NPM packages (package.json
), Ruby gems (Gemfile
), and so on.
But in Python, everything you install with pip
is global. Anything you install with pip will make your system Python installation messy at best and at worst will not be portable between developer machines. We get around this problem with the concept of a virtual environment which more or less is a copy of whatever Python version you're using self-contained to a project.
pipenv
works pretty similarly to npm
.
You initialise with pipenv --three
and use pipenv install Flask
(for example) to install packages and keep track of them in Pipfile.toml
and a lock file. You can then clone it on another computer and pipfile install
to install all dependencies.
If this tool does not work for you, you may also want to try pyenv
and virtualenv
and use a requirements.txt
file as suggested by Rahul.
Hope that helps!

- 701
- 2
- 8
- 23