How To Install/Uninstall Python Packages In Anaconda Virtual Environment Successfully

There are 3 ways to install/uninstall python packages in anaconda, this article will tell you them one by one.

1. Install / Uninstall Python Packages In Anaconda Navigator Window.

1.1 Go To Anaconda Navigator Virtual Environment Python Packages List Window.

  1. If you use Windows, then click Windows Start Menu —> Anaconda3 —> Anaconda Navigator menu item to open it.
  2. Then click the Environments menu item in the opened Anaconda Navigator Window left menu list.
  3. Click to select one existing anaconda virtual environment in the middle environments list.
  4. Then you will find there is a drop-down list on the right panel top area.
  5. There are 5 drop-down items in the list, they are Installed, Not installed, Updatable, Selected, and All.
  6. There is also a Search Packages search box behind the drop-down list, you can search the python packages by input the search keyword and search.

1.2 Install Python Packages From Anaconda Navigator Python Packages List Window Steps.

  1. To install one python package, you can select the Not installed menu item from the drop-down list, then input the search keyword such as pandas in the Search Packages search box and click enter key.
  2. Then it will list all the python packages that the name contains the keyword pandas.
  3. Check the checkbox before the python packages to select them, then click the Apply button on the bottom right corner of the window to install it.
  4. It will popup an Install Packages window to display all the dependencies packages, then click the Apply button in the popup window to install them.

1.3 Uninstall Python Packages From Anaconda Navigator Python Packages List Window Steps.

  1. Select the Installed menu item from the above drop-down list.
  2. Input the installed python packages name in the Search Packages search box and click enter key to search it out.
  3. Click the checkbox before the python package, then it will pop up a menu list.
  4. Click the Mark for removal menu item in the above popup menu list, then the checkbox will be changed to a red square.
  5. After you select all the python packages that you want to remove, click the Apply button to remove them all.
  6. Then it will popup the Remove Packages window, it will list all the dependencies python library in the window. After you confirm it, you can click the Apply button in the Remove Packages window to remove them successfully.

2. Install / Uninstall Python Packages Through Conda Command.

  1. Open the Anaconda Navigator window, and click the Environments menu item in the window left side to list all the Anaconda virtual environments.
  2. Click the green triangle at the end of one anaconda virtual environment,  and then click the Open Terminal menu item in the popup menu list.
  3. It will open a dos window or a terminal window and enter your selected anaconda virtual environment.
  4. Run the command conda install package-name to install the python package like below.
    (MyPythonEnv) C:\Users\zhaosong>conda install Numpy
    Collecting package metadata (current_repodata.json): done
    Solving environment: done
    
    
    ==> WARNING: A newer version of conda exists. <== current version: 4.10.1 latest version: 4.10.3 Please update conda by running $ conda update -n base -c defaults conda ## Package Plan ## environment location: C:\Users\zhaosong\anaconda3\envs\MyPythonEnv added / updated specs: - numpy The following packages will be downloaded: package | build ---------------------------|----------------- certifi-2021.5.30 | py38haa95532_0 140 KB mkl-2021.3.0 | haa95532_524 113.7 MB mkl-service-2.4.0 | py38h2bbff1b_0 51 KB mkl_fft-1.3.0 | py38h277e83a_2 137 KB mkl_random-1.2.2 | py38hf11a4ad_0 225 KB numpy-1.20.3 | py38ha4e8547_0 23 KB numpy-base-1.20.3 | py38hc2deb75_0 4.2 MB openssl-1.1.1l | h2bbff1b_0 4.8 MB ------------------------------------------------------------ Total: 123.3 MB The following NEW packages will be INSTALLED: blas pkgs/main/win-64::blas-1.0-mkl intel-openmp pkgs/main/win-64::intel-openmp-2021.3.0-haa95532_3372 mkl pkgs/main/win-64::mkl-2021.3.0-haa95532_524 mkl-service pkgs/main/win-64::mkl-service-2.4.0-py38h2bbff1b_0 mkl_fft pkgs/main/win-64::mkl_fft-1.3.0-py38h277e83a_2 mkl_random pkgs/main/win-64::mkl_random-1.2.2-py38hf11a4ad_0 numpy pkgs/main/win-64::numpy-1.20.3-py38ha4e8547_0 numpy-base pkgs/main/win-64::numpy-base-1.20.3-py38hc2deb75_0 The following packages will be UPDATED: ca-certificates 2021.4.13-haa95532_1 --> 2021.9.30-haa95532_1
      certifi                          2020.12.5-py38haa95532_0 --> 2021.5.30-py38haa95532_0
      openssl                                 1.1.1k-h2bbff1b_0 --> 1.1.1l-h2bbff1b_0
    
    
    Proceed ([y]/n)? y
    
    
    Downloading and Extracting Packages
    numpy-1.20.3         | 23 KB     | ################################################################################################################################################################################################# | 100%
    openssl-1.1.1l       | 4.8 MB    | ################################################################################################################################################################################################# | 100%
    certifi-2021.5.30    | 140 KB    | ################################################################################################################################################################################################# | 100%
    mkl-service-2.4.0    | 51 KB     | ################################################################################################################################################################################################# | 100%
    numpy-base-1.20.3    | 4.2 MB    | ################################################################################################################################################################################################# | 100%
    mkl_fft-1.3.0        | 137 KB    | ################################################################################################################################################################################################# | 100%
    mkl_random-1.2.2     | 225 KB    | ################################################################################################################################################################################################# | 100%
    mkl-2021.3.0         | 113.7 MB  | ################################################################################################################################################################################################# | 100%
    Preparing transaction: done
    Verifying transaction: done
    Executing transaction: done
    
  5. After you successfully install the python package, you can run the command conda list package-name to verify that it has been installed.
    (MyPythonEnv) C:\Users\zhaosong>conda list Numpy
    # packages in environment at C:\Users\zhaosong\anaconda3\envs\MyPythonEnv:
    #
    # Name                    Version                   Build  Channel
    numpy                     1.20.3           py38ha4e8547_0
    numpy-base                1.20.3           py38hc2deb75_0
    
  6. To uninstall a python package, you can run the command conda uninstall package-name.
    (MyPythonEnv) C:\Users\zhaosong>conda uninstall Numpy
    
  7. You can run the command conda list package-name again to verify the uninstall result.
    (Python27) C:\Users\zhaosong>conda list Numpy
    # packages in environment at C:\Users\zhaosong\anaconda3\envs\Python27:
    #
    # Name                    Version                   Build  Channel

3. Install / Uninstall Python Packages Through PIP Command.

  1. Run the command pip install package-name to install the python package as below.
    (MyPythonEnv) C:\Users\zhaosong>pip install Numpy
    Collecting Numpy
      Downloading numpy-1.21.2-cp38-cp38-win_amd64.whl (14.0 MB)
         |████████████████████████████████| 14.0 MB 1.6 kB/s
    Installing collected packages: Numpy
    Successfully installed Numpy-1.21.2
  2. If you meet the error message such as ValueError: check_hostname requires server_hostname like below, this is because you are using some proxy server ( for example SSR or v2ray) to access the internet, to fix the error just close and exit the  proxy server that you are using.
    ERROR: Exception:
    Traceback (most recent call last):
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\cli\base_command.py", line 173, in _main
        status = self.run(options, args)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\cli\req_command.py", line 203, in wrapper
        return func(self, options, args)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\commands\install.py", line 315, in run
        requirement_set = resolver.resolve(
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 94, in resolve
        result = self._result = resolver.resolve(
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 472, in resolve
        state = resolution.resolve(requirements, max_rounds=max_rounds)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 341, in resolve
        self._add_to_criteria(self.state.criteria, r, parent=None)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 172, in _add_to_criteria
        if not criterion.candidates:
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 151, in __bool__
        return bool(self._sequence)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 140, in __bool__
        return any(self)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 128, in <genexpr>
        return (c for c in iterator if id(c) not in self._incompatible_ids)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 29, in _iter_built
        for version, func in infos:
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 272, in iter_index_candidate_infos
        result = self._finder.find_best_candidate(
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\index\package_finder.py", line 851, in find_best_candidate
        candidates = self.find_all_candidates(project_name)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\index\package_finder.py", line 798, in find_all_candidates
        page_candidates = list(page_candidates_it)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\index\sources.py", line 134, in page_candidates
        yield from self._candidates_from_page(self._link)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\index\package_finder.py", line 758, in process_project_url
        html_page = self._link_collector.fetch_page(project_url)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\index\collector.py", line 490, in fetch_page
        return _get_html_page(location, session=self.session)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\index\collector.py", line 400, in _get_html_page
        resp = _get_html_response(url, session=session)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\index\collector.py", line 115, in _get_html_response
        resp = session.get(
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\requests\sessions.py", line 555, in get
        return self.request('GET', url, **kwargs)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_internal\network\session.py", line 454, in request
        return super().request(method, url, *args, **kwargs)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\requests\sessions.py", line 542, in request
        resp = self.send(prep, **send_kwargs)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\requests\sessions.py", line 655, in send
        r = adapter.send(request, **kwargs)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\cachecontrol\adapter.py", line 53, in send
        resp = super(CacheControlAdapter, self).send(request, **kw)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\requests\adapters.py", line 439, in send
        resp = conn.urlopen(
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 696, in urlopen
        self._prepare_proxy(conn)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 964, in _prepare_proxy
        conn.connect()
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\urllib3\connection.py", line 359, in connect
        conn = self._connect_tls_proxy(hostname, conn)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\urllib3\connection.py", line 500, in _connect_tls_proxy
        return ssl_wrap_socket(
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 453, in ssl_wrap_socket
        ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 495, in _ssl_wrap_socket_impl
        return ssl_context.wrap_socket(sock)
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\ssl.py", line 500, in wrap_socket
        return self.sslsocket_class._create(
      File "C:\Users\zhaosong\anaconda3\envs\MyPythonEnv\lib\ssl.py", line 997, in _create
        raise ValueError("check_hostname requires server_hostname")
    ValueError: check_hostname requires server_hostname
  3. After you install the python package, you can run the command pip show Numpy to verify the python package installation.
    (MyPythonEnv) C:\Users\zhaosong>pip show Numpy
    Name: numpy
    Version: 1.21.2
    Summary: NumPy is the fundamental package for array computing with Python.
    Home-page: https://www.numpy.org
    Author: Travis E. Oliphant et al.
    Author-email:
    License: BSD
    Location: c:\users\zhaosong\anaconda3\envs\mypythonenv\lib\site-packages
    Requires:
    Required-by:
  4. To uninstall the python package, just run the command pip uninstall package-name.
    (MyPythonEnv) C:\Users\zhaosong>pip uninstall Numpy
    Found existing installation: numpy 1.21.2
    Uninstalling numpy-1.21.2:
      Would remove:
        c:\users\zhaosong\anaconda3\envs\mypythonenv\lib\site-packages\numpy-1.21.2.dist-info\*
        c:\users\zhaosong\anaconda3\envs\mypythonenv\lib\site-packages\numpy\*
        c:\users\zhaosong\anaconda3\envs\mypythonenv\scripts\f2py.exe
    Proceed (Y/n)? Y
      Successfully uninstalled numpy-1.21.2
    
    (MyPythonEnv) C:\Users\zhaosong>pip show  Numpy
    WARNING: Package(s) not found: Numpy
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x