![]() ![]() ![]() The ‘ -f’ flag stands for file and the filename of the YAML file should immediately follow the ‘ -f’ flag. If that file were called ‘ environment.yml’, then I could create the environment using the command below: conda env create -f environment.yml Your YAML file may look something like this: name: your_env_name channels: - defaults dependencies: - ca-certificates=2018.03.07=0 prefix: /Users/your_username/anaconda3/envs/your_env_name If you didn’t want to create the environment from the command line for those reasons or others, you could create a YAML (YAML Ain’t Markup Language) file, which acts like a configuration file. Even worse, the command may not remain in your shell history and if you wanted to recreate the exact same environment in the future, it would be very tedious if not difficult. So you could somewhat manually add all of the packages you need, but that may be tedious if you have many packages besides that, there would be a lot of typing involved on the command line and a slip of the finger may cause you to reenter the command. The ‘ conda create’ command will effectively load all of the packages at once, which is preferable to loading them in 1 at a time as that can lead to dependency conflicts. conda create -name your_env_name python=3.7 scipy=0.15.0 astroid babel The ‘ -y’ flag essentially tells the command line to say ‘yes’ to all of the prompts that follow it isn’t strictly necessary but it does save you a little hassle. In other snippets you see online, you may see ‘ -n’ instead of ‘ - name’ they mean exactly the same thing. ![]() In this command, the ‘ python=3.7’ portion specifies which version of python I want to set up the environment in you can change the version to whatever suits your needs. To quickly create an environment using conda, you can type in the command: conda create -name your_env_name python=3.7 -y For reference, I run my commands on the Terminal on Mac OS X. This guide will presume that you already have Anaconda or miniconda installed all the instructions will also be on the bash command line. There are some arguments as to why you should choose conda over virtualenv as outlined in Myth #5 in this blog post, but I’ll just focus on how to use conda in this guide since that’s a popular tool for data science, which is what I’m focused on right now. There are multiple ways of creating an environment, including using virtualenv, venv (built in to the Python 3 standard library), and conda, the package manager associated with Anaconda. Additionally, package managers for other languages, like JavaScript’s NPM ( Node Package Manager), take care of most of these details for you, but you’ll have to get your hands dirty in Python and deal with the environments yourself. For those more familiar with programming, virtual environments are analogous to Docker containers. Virtual environments keep these dependencies in separate “sandboxes” so you can switch between both applications easily and get them running. This is where virtual environments become useful. If I try running both at once on Python 2 or Python 3, one of them may break because some of the code that runs on Python 2 doesn’t run on Python 3 or vice versa. But we may have many projects on our computer, perhaps a Flask app that runs on version 0.11 (the first one you made!) and Python 2.7 and even a more modern Flask app that runs on version 0.12 and Python 3.4. Likewise, we may need to use specific versions of the libraries for similar reasons. And sometimes when we create software, the software needs to run on a specific version of the language because our software expects a certain behavior that is present in older versions but changes in newer versions. Python, like many other programming languages, has different versions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |