💡 Most of the information in this guide derives from: https://whiteboxml.com/blog/the-definitive-guide-to-python-virtual-environments-with-conda
Why I chose this setup
I have worked with other libraries such as Pyenv, Virtualenv, etc and Conda seems to include the most straightforward setup and long term project organization, and minimal maintenance requirements.
When you are finished with this guide you will be able to:
- Create a contained workspace for your python project
- Add any extra dependencies for your project to use
- Avoid problems related to incompatible python and pip versions
What is Conda
Conda is a virtual env manager. Definition of virtual environment in this context is that it is an isolated installation of python and its libraries.
Uses for Conda
- Manages virtual environments: it creates, deletes, or packages virtual environments.
- Install libraries from conda repositories (also called channels): it allows to install software inside a virtual environment. This software includes entire programming languages like Python, R, or Java, libraries like pandas or scikit-learn, or even software like htop, tmux or a full fledged PostgreSQL database.
Conda and pip are often mistaken as competitors because they can both be used to handle use case #2, but most of the time there is no difference when installing with Conda or pip. Pip catalog is generally more complete while the conda dependency resolvers is more robust.
How to install miniConda
- Visit: https://docs.conda.io/en/latest/miniconda.html
- Download based on your operating sytem (Windows, macOS, or Linux) from the options listed under "Latest Miniconda Installer Links"
- I recommend using the bash installer (.sh file) for macOS. You can use the graphical installer (.pkg) if you'd like
- Run the bash script from your terminal or command prompt
- You will be prompted to answer Y or n to the terms. Answer Y.
- The installer will ask for an install location, I recommend leaving it as the default
- The installer will ask you if you want to initialize Conda. Answer Yes. This will place Conda on your so that you are able to access it whenever you open your terminal
- Done
Check that Conda is installed
- Open a new terminal or command prompt window
- Type in your prompt and enter
- You should see a list of options show up
- Type next and you should see information about your Conda installation
General boilerplate for setting up new environments
The general steps when setting up the environment for your python project is to navigate to the directory that your project is in. Then, create the Conda environment and install any packages you may need in order to run your project.
Loading...
If you run into any trouble when running and to check where they are installed, this stack overflow link may help.
Best Practice for Most Projects
When it comes to installing dependencies we recommend using the pip downloaded to your virtual env.
Also pip freeze tends to save more than just the top-level dependencies consumed by your project. In order to overcome this, and produce a "clean" (easier to read) file, I recommend using . There are other packages that do this(such as ) but I have found pipreqs to work well.
Install and use pipreqs
Loading...
Now you're ready to get started on your own python projects. We're excited to see what you create!
About Alpaca
Hey there! My name is Alpaca and I am the creator and sole author of all the content found on this site. I currently live in my hometown of MIT License and enjoy writing about topics related to artificial intelligence and its applications. When I'm not busy developing cutting edge technologies, I enjoy taking virtual strolls through nature, binge watching sci-fi movies, and trying to beat high scores at arcade classics - usually with success.