Original source: Fish Heart Fishstar
Are you going to learn Python to do data analysis, do you get into all sorts of trouble at the beginning?
- What's the Python2 or the Python3?
- Why is it always wrong to install Python?
- How to install the tool kit?
- Why do I need to install a bunch of other unknown tools before installing this tool?
I believe most of the beginners in Python have had a headache for the environment, but you are not alone, and everyone is so upset. In order to avoid detours when getting started, and to keep the enthusiasm of the upswing from being too hard, it is recommended to use Anaconda to manage your installation environment and the various toolkits.
This article describes the use of Anaconda, the full text outline is as follows:
- Why Choose Anaconda
- What is Anaconda
- What is Conda
- Advantages of Anaconda
- How to install Anaconda
- How to manage Python packages
- How to manage the Python environment
First, why Choose Anaconda? 1.1 What is Anaconda?
Anaconda is a Python release that focuses on data analysis and contains more than 190 science packages, including Conda, Python, and their dependencies. As a curious baby you are not found a term Conda, then you will certainly ask Conda what is it?
1.2 What is Conda?
Conda is a management system for open source packages (packages) and virtual environments (environment).
- Packages Management: You can use Conda to install, update, uninstall toolkits, and it is more focused on data science-related toolkits. Packages such as Numpy, Scipy, Pandas, Scikit-learn, which are commonly used in data analysis, are pre-integrated when Anaconda is installed. Also worth mentioning is that Conda not only manages Python's toolkit, it can also install non-Python packages. For example, in the new version of Anaconda can be installed in the R Language integrated development environment Rstudio.
- Virtual Environment Management: in Conda, you can establish multiple virtual environments to isolate different versions of the toolkit required by different projects to prevent conflicts on the version. For those of you who are entangled in the Python version, we can also build Python2 and Python3 environments to run different versions of Python code separately.
Knowing what it is , we also need to ask why. So why choose to use Anaconda?
What are the advantages of 1.3 Anaconda?
Anaconda advantages summed up on eight words: Save time worry, analysis of the weapon.
- save time and worry: Anaconda simplifies your workflow with the Management Toolkit, development environment, and Python version. It is not only easy to install, update, uninstall the toolkit, but also to install the appropriate dependencies automatically, while you can use different virtual environments to isolate the different requirements of the project.
- Anaconda : the Python tool for enterprise-class big data analytics, which is how you advertise yourself in the official website. It contains more than 720 open source packages related to data science, and is involved in data visualization, machine learning, deep learning and many more. Not only can do data analysis, can even be used in the field of big data and artificial intelligence.
After solving the question of what and why , let's look at how to doit.
Second, how to install anaconda?
You can download the Anaconda installer from here and view the installation instructions. Whether it's Windows, Linux or MAC's OSX system, you can find the corresponding installation software. If your computer is 64 bits, choose the 64-bit version as much as possible. As for the Python version is 2.7 or 3.x, it is recommended that you use Python3, because Python2 will eventually stop maintenance. While most of the tutorials available today are Python2, there's no need to worry because you can manage two Python versions of the environment in Anaconda.
Follow the prompts to install, you will probably be surprised to find that the computer has a lot of applications, do not worry, we see in one item:
- Anaconda navigtor : A graphical user interface for managing toolkits and environments, and many of the subsequent management commands can be implemented manually in Navigator.
- Jupyter Notebook : A Web-based, interactive computing environment that allows you to edit documents that are easy to read and to demonstrate the process of data analysis.
- qtconsole : An executable IPython graphical interface program, compared to the Python Shell interface, Qtconsole can directly display code-generated graphics, implement multi-line code input execution, as well as built in many useful functions and functions.
- Spyder : An integrated development environment that uses Python language, cross-platform, and scientific operations.
After the installation is complete, we also need to upgrade all the toolkits to avoid possible errors. Open the terminal of your computer and enter it at the command line:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda Upgrade--all</textarea>
Enter when the terminal asks whether to install the following upgrade version y
.
In some cases, you may encounter an error message that cannot be found for the Conda command, which is most likely an issue with the environment path setting, and you need to add the Conda environment variable: export PATH=xxx/anaconda/bin:$PATH
where xxx is replaced with the Anaconda installation path.
Now that the installation is complete, let's look at how to manage the toolkit and environment with Anaconda.
Third, how to manage Python package?
Install a package:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda Install package_name</textarea>
1 |
Conda Install package_name |
Here Package_name is the name of the package that needs to be installed. You can also install multiple packages at the same time, such as installing NumPy, scipy, and pandas, and execute the following command:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda Install numpy scipy Pandas</textarea>
1 |
Conda Install NumPy scipy Pandas |
You can also specify the version of the installation, such as installing the 1.1 version of NumPy:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda Install numpy=1.10</textarea>
1 |
Conda Install NumPy = 1.10 |
Removing a package:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda Remove Package_name</textarea>
1 |
Conda Remove package_name |
Upgrade Package Version:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda Update Package_name</textarea>
1 |
Conda Update package_name |
See All packages:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda List</textarea>
If you can't remember the specific name of the package, you can also make a fuzzy query:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda Search Search_term</textarea>
1 |
Conda Search Search_term |
Iv. How to manage the python environment?
The default environment is root, and you can create a new environment:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda create-n env_name List of packages</textarea>
1 |
Conda Create -n env_name List of packages |
This -n
represents name, which env_name
is the name of the environment that needs to be created, and the toolkit that list of packages
needs to be installed in the new environment.
For example, when I install the Python3 version of Anaconda, the default root environment is naturally Python3, but I also need to create a Python 2 environment to run the old version of Python code, preferably with the pandas package installed, so we run the following command To create:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda create-n py2 python=2.7 Pandas</textarea>
1 |
Conda Create -n py2 python = 2.7 Pandas |
Careful you will find, PY2 environment not only installed pandas, but also installed a series of packages NumPy, which is the convenience of using Conda, it will automatically install the corresponding dependent package for you, and do not need you to manually install.
Enter an environment named Env_name:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Source Activate Env_name</textarea>
1 |
Source Activate Env_name |
Exit the current environment:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Source Deactivate</textarea>
Also note that in Windows systems, use activate env_name
and deactivate
to enter and exit an environment.
To remove an environment named Env_name:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda env remove-n env_name</textarea>
1 |
Conda Env Remove - n env_name |
Show All environments:
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda env List</textarea>
When sharing the code, but also need to share the environment to everyone, execute the following command can be in the current environment of the package information into the YAML file named environment.
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda env export > Environment.yaml</textarea>
1 |
Conda Env Export > Environment. Yaml |
Similarly, when you execute someone else's code, you also need to configure the appropriate environment. You can use the YAML file you share to create a touch-like environment.
<textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly="" style="font-size: 13px !important; line-height: 15px !important; z-index: 0; opacity: 0">Conda env create-f Environment.yaml</textarea>
1 |
Conda Env Create - F environment. Yaml |
At this point, you have entered the gate of the Anaconda, you can roam in the sea of Python in the future.
Wish you a happy study!
Note: The code examples in this article refer to the Anaconda section of the Udacity data Analysis course.
<!-- BEGIN #author-bio -->
</div>
For beginners to Python: Anaconda Getting Started using the guide