Pip change python path

how to reinstall pip or change directory path

I have been getting the same error whenever I tried to install modules using pip, using mac. I think it may because I was changing the path and accidentally change the pip path. I tried installing pip again through many methods but it still didn’t work, especially when I tried to use pip to reinstall. I was wondering would there be any chance that I can maybe fix it with changing the path or something? Thanks

ERROR: Exception: Traceback (most recent call last): File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 188, in main status = self.run(options, args) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 454, in run self._handle_target_dir( File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 460, in _handle_target_dir ensure_dir(target_dir) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/utils/misc.py", line 142, in ensure_dir os.makedirs(path) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/os.py", line 213, in makedirs makedirs(head, exist_ok=exist_ok) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/os.py", line 213, in makedirs makedirs(head, exist_ok=exist_ok) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/os.py", line 213, in makedirs makedirs(head, exist_ok=exist_ok) [Previous line repeated 2 more times] File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/os.py", line 223, in makedirs mkdir(name, mode) OSError: [Errno 30] Read-only file system: '/urs' 

Источник

Change Pip Install Location

Python-pip, by default, installs packages on a global scope – for all users. In Unix-based systems, the packages are installed on /usr/local/bin/ whereas, on Windows, they are located in the Program Files directory.

Читайте также:  Java printf для double

This article focuses on the cases we are interested in installing Python packages in a specific folder. We will also explain how to use and remove packages installed in this manner.

There are two ways to install packages to a particular directory – through the terminal (command line) and by editing the pip configuration file.

Method 1: Through the terminal/ command line

When installing the modules using pip on the terminal or Windows PowerShell, we have a “target” option or short-hand “t” that allows us to specify the directory to which we want packages to be installed. The general syntax is as shown below

Here is an example of how I installed NumPy to the “test_modules” folder on my Desktop,

Method 2: Editing pip Configuration file

You can also specify the default pip installation location in the configuration file, which is located in the following path based on the OS (you may have to create these paths and files):

Unix and Mac OS

$HOME is the home directory of the current user on Linux/Mac, usually located at /home/. It can also be written as a tilde (~). On Windows, the home directory %HOME% is located in C:\Users\ for the logged-in user. Like in Linux, the ~ also means home folder when using WindowsPowerShell.

Example (Linux)

At the start, the directory does not exist, so I have to create the pip directory and add the configuration file pip.config inside it. Executed the following command on the terminal:

mkdir -p ~/.config/pip && touch ~/.config/pip/pip.conf

(“p” option allows us to create a folder within a folder if there’s a need, whereas && enables us to join two commands into one line.).

That creates an empty configuration file. On the file, we define the default installation location with the following general syntax:

In our example, we want to install packages on the “test_modules2″ directory on the Desktop. The file ~/.config/pip/pip.config will have the following contents:

[global] target=~/Desktop/test_modules2

On installing Python packages now, they are installed on the above directory. See below.

Example (Windows)

First of all, we need the pip.ini file. To get that, we run the following command on Windows PowerShell (of course, you can also create files and folders on the GUI):

The semi-colon (;) is used to combine two commands in one line, and cd > creates an empty file, that is to say, the command cd > ~\pip\pip.ini in our case creates a pip.ini file within the pip folder in the home directory (C:\Users\ ).

Next, we need to specify the target directory in the configuration file pip.ini. For that, we add the following content to the configuration file:

Where is the default directory for pip installation going forward unless you change the settings on the configuration file.

Note: If the target directory indicated on the config file does not exist, it is created. You can read more about the pip configuration file in the pip documentation.

Removing Packages Installed Using the Above Methods

To remove the packages installed in the above methods, delete the folders with the installed package(s). Remember to remove the settings on the configuration file if you no longer need them and want to go to default.

(Important) Remark on Usage of Modules Installed as Above

After setting the default pip installation location, Python may continue looking for installed modules on the default paths. If you want to learn how to import packages from the location we just created with the above methods, see this article.

Источник

How to specify the python path for pip?

enter image description here

With pip installed, I am trying to install matplotlib in Ubuntu 12.04.4 LTS. I got the following error when executing «sudo pip install matplotlib» I guess this is because the python version is too old (2.7.3), So I follow this discussion, How to install the latest Python version on Debian separately or upgrade?, to build the latest 2.7.11 in /opt/python/. My question is how to specify the newer version of python when installing matplotlib through pip? Or should I just use «easy_install», which is not recommended by other people? Thank you for precious time on my question.

2 Answers 2

Pip is bundled with Python 2.7.11 (they started adding it in 2.7.9 and 3.4), so you can use an included module to generate a short pip script:

$ /opt/python/bin/python -m ensurepip 

That will make /opt/python/bin/pip , which has a shebang line pointing at /opt/python/bin/python , so you can run it when you want a pip that’s associated with that particular Python installation.

If you’re running an older Python, you can download get-pip.py and pass it to the Python you want to install it under:

$ wget 'https://bootstrap.pypa.io/get-pip.py' $ /opt/python/bin/python ./get-pip.py 

This will generate the same pip scripts. See the pip documentation for more information

Источник

Change path of pip and pip3

I want to create a user path to install packages installed by pip or pip3 for python 3.7.2, for that, I noticed that C:\Users\VVK\AppData\Roaming\Python\Python37\site-packages by py -m site —user-site and, I wish to update it by C:\Users\VVK\AppData\Roaming\Python37\Scripts , How is this possible? I am using Microsoft Windows 10 64-bit.

1 Answer 1

Python37\site-packages is used to install libraries while Python37\Scripts is used to install programs. The latter should not be used for package installation. Packages when installed should install their programs (executable scripts) into Python37\Scripts themselves.

Differentiate between a library, a package, a program and what is their order of preference?, For eg, a library contains a collection of packages, a package contains a collection of programs. Please! refer the web link at docs.python-guide.org/dev/virtualenvs, in that link please read this section, in the webpage, On Windows, you can find the user base binary directory by running py -m site —user-site and replacing site-packages with Scripts. For example, this could return C:\Users\Username\AppData\Roaming\Python36\site-packages so you would need to set your PATH to include.

The problem is that the word package is heavily overloaded. A package is a directory with file __init__.py ; every *.py is a module; packages and modules can be imported with import . But a package is also a distribution format (egg or wheel). A library is a set of packages (in the 1st sense). And a package (2nd) contains libraries and executable scripts. When a package is installed libraries go to site-packages directories (system-wide, or user-owned, or in a virtialenv) while scripts go to Scripts directory. Scripts are program to execute; they import packages (1st) and modules.

Источник

Оцените статью