How to view the location of installed packages in a Conda virtual environment:
Method 1: Use the Conda command
The Conda environment was activated. Run the following command:
conda list --explicit
This command lists all installed packages and their full paths in the current environment. For example:
# This file may be used to create an environment using: # $ conda create --name <env> --file <this file> # platform: linux-64 @EXPLICIT /pkgs/main/linux-64/python-3.8.8-h7579374_0.tar.bz2 /pkgs/main/linux-64/numpy-1.20.1-py38h50ba1cc_0.tar.bz2
Each behavior is a package, and the URL after it contains the source and installation location of the package.
Method 2: View in Python
If you have activated the environment and started the Python interpreter, you can get the location of the package through the following code:
import <package_name> print(<package_name>.__file__)
For example, if you want to viewnumpy
Installation location:
import numpy print(numpy.__file__)
This will outputnumpy
The main file path of the module is similar to:
/home/user/miniconda3/envs/myenv/lib/python3.8/site-packages/numpy/__init__.py
Method 3: Use the pip command
If you're more usedpip
, you can run the following command:
pip show <package_name>
This displays detailed information about the package, including the source and installation location of the package. For example:
pip show numpy
The output may be similar to:
Name: numpy Version: 1.20.1 Summary: NumPy is a general-purpose array-processing package. Home-page: Author: NumPy Developers Author-email: numpy-discussion@ License: BSD-3-Clause Location: /home/user/miniconda3/envs/myenv/lib/python3.8/site-packages Requires: Required-by:
Method 4: Check the environment directory structure
The default installation path for the Conda virtual environment is usually:
<conda root>/envs/<env_name>/
in<conda root>
It is the installation directory of Conda (for example/home/user/miniconda3
)。
Packages are usually installed in the following subdirectories:
<conda root>/envs/<env_name>/lib//site-packages/
You can navigate directly to the directory and view installed packages.
Summarize
- Method 1andMethod 2is the most commonly used method, which is suitable for command line and Python interactive environments respectively.
-
Method 3Suitable for use
pip
Management package situation, although Conda also supportspip
Install. - Method 4is a more general method that is suitable for viewing the installation location of all packages in the environment.
This is the article about the example method of viewing package location in the conda virtual environment. For more related content on viewing package location in the conda virtual environment, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!