I'm trying to create a requirements.txt for my project.
I got the file with pip freeze > requirements.txt but I have some questions about it.
Basically I have a ton of libraries on my PC, so I only want the ones for my project in requirements.txt.
If for example, I remove all libraries from the file and only leave awscli, will awscli dependencies install when the user runs pip install -r requirements.txt? Or will I need to keep every dependency of every library inside the file?
Yes, they will. However, based on your question, I assume you need to familiarize yourself with a concept called virtual environments.
Related
Im new to Robotframework coming from java-selenium background. I have created tested cases using libraries robotframework-requestlibrary, seleniumlibrary. I installed these using pip install, but now if I want to pass on my test-scripts, others will not be able to run as they also need to install these libraries.
How we specify libraries used in Robot Framework like we have pom.xml in Java and mvn clean install will get it setup for others.
Step 1: Use freeze cmd in your machine in command line to get the libraries installed with version no.
pip freeze > requirements.txt
Step 2: Include this requirements.txt file while giving your test scripts to others and ask them to run the below command in command line before they run the robot scripts
Note: open command line in the requirements.txt file path
pip install -r requirements.txt
That's it!
Long story short, I messed with my Python environment too much (moving files around, creating new folders, trying to reinstall packages, deleting files etc.) My google package doesn't work anymore. Everytime I try to import the package, it says it can't find the module, even though I did a pip install.
I was wondering how I could do a hard reset/delete python off my computer and reinstall it.
Thanks.
is your pip working try extracting the required modules.
pip freeze > requirements.txt
create new Venv
pip install -r requirements.txt
I figured it out. My pip was installing to a site packages folder inside a local folder, while my jupyter notebook was trying to pull from the anaconda site packages folder.
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
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.
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!
i have a virtualenv called alpha but after upgrading my ubuntu 18 to ubuntu 19, now i cant install any python package into my virtualenv, basically i cant use pip3 command. whenever i use pip3 command i got this error: ImportError: cannot import name 'dist' (i have tried: sudo apt install python3-dist-utils but its not working). Now because i cant use pip3 command i cant create requirements.txt file. i want to remove my old alpha virtualenv and want to install new one and install all the dependencies using requirements.txt file, but i can't do that because i can't create requirements.txt. How do i solve this problem ?
Edit
Because i have so many libraries installed in my virtualenv(i cant even remember them). first i want to recover all the dependency information's and then want to install new one. I CANT JUST REMOVE THE VIRTUALENV FIRST.
There's no package like dist-utils, you are looking for python3-dist-utils.
I want to make a .txt file with all the python packages my environment is using, and include it in the git repo, so that anyone who needs to run the code, can just make an environment, install all the packages from the list and use it.
I have two questions, first, how can I create that .txt files with all the installed packages? Second, how can someone with the .txt file install everything from it (using pip3?) in their fresh anaconda environment?
After activating your environment, you can do this:
pip freeze > requirements.txt
And to install all these packages in a fresh environment:
pip install -r requirements.txt
Hope this helps!