python更改安装位置,如何更改pip的默认安装位置

I'm trying to install Pandas using pip, but I'm having a bit of trouble. I just ran sudo pip install pandas which successfully downloaded pandas. However, it did not get downloaded to the location that I wanted. Here's what I see when I use pip show pandas:

---

Name: pandas

Version: 0.14.0

Location: /Library/Python/2.7/site-packages/pandas-0.14.0-py2.7-macosx-10.9-intel.egg

Requires: python-dateutil, pytz, numpy

So it is installed. But I was confused when I created a new Python Project and searched under System Libs/lib/python for pandas, because it didn't show up. Some of the other packages that I've downloaded in the past did show up, however, so I tried to take a look at where those were. Running pip show numpy (which I can import with no problem) yielded:

---

Name: numpy

Version: 1.6.2

Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

Requires:

Which is in a completely different directory. For the sake of confirming my error, I ran pip install pyquery to see where it would be downloaded to, and got:

Name: pyquery

Version: 1.2.8

Location: /Library/Python/2.7/site-packages

Requires: lxml, cssselect

So the same place as pandas...

How do I change the default download location for pip so that these packages are downloaded to the same location that numpy is in?

Note: There were a few similar questions that I saw when searching for a solution, but I didn't see anything that mentioned permanently changing the default location.

解决方案

According to pip documentation at

You will need to specify the default install location within a pip.ini file, which, also according to the website above is usually located as follows

On Unix and Mac OS X the configuration file is: $HOME/.pip/pip.conf

On Windows, the configuration file is: %HOME%\pip\pip.ini

The %HOME% is located in C:\Users\Bob on windows assuming your name is Bob

On linux the $HOME directory can be located by using cd ~

You may have to create the pip.ini file when you find your pip directory. Within your pip.ini or pip.config you will then need to put (assuming your on windows) something like

[global]

target=C:\Users\Bob\Desktop

Except that you would replace C:\Users\Bob\Desktop with whatever path you desire. If you are on Linux you would replace it with something like /usr/local/your/path

After saving the command would then be

pip install pandas

However, the program you install might assume it will be installed in a certain directory and might not work as a result of being installed elsewhere.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 你可以使用以下命令更改pip路径: 1. 打开终端或命令提示符 2. 输入以下命令:pip config set global.target /path/to/new/pip 3. 将“/path/to/new/pip”替换为你想要设置的新路径 4. 按回车键确认命令 这将更改pip默认路径。请注意,你需要具有管理员权限才能更改pip路径。 ### 回答2: 在Python中,pip是一个常用的包管理工具,用于安装、卸载和更新第三方库。pip默认安装路径是Python安装路径下的Scripts文件夹。 要更改pip默认路径,可以按照以下步骤操作: 1. 首先,打开命令提示符或终端窗口。 2. 输入以下命令来查看pip默认路径: ``` pip show pip ``` 3. 在显示的结果中,找到Location一行,表示pip安装路径。 4. 创建一个新的文件夹来作为pip的新路径,例如,我创建了一个名为pip_new的文件夹。 5. 使用文本编辑器打开pip的配置文件pip.ini(如果不存在则创建一个),这个配置文件通常位于用户目录下的%APPDATA%\pip目录中。 6. 在配置文件中添加以下内容,指定pip的新路径: ``` [global] target = c:\path\to\pip_new ``` 7. 保存并关闭配置文件。 8. 在命令提示符或终端窗口中,输入以下命令来卸载pip: ``` python -m pip uninstall pip ``` 9. 然后,输入以下命令来重新安装pip,并指定新的路径: ``` python get-pip.py --target=c:\path\to\pip_new ``` 这里的get-pip.py是pip安装脚本,你可以从Python的官方网站下载最新版本的get-pip.py。 10. 安装完成后,再次输入以下命令来查看pip的新路径是否生效: ``` pip show pip ``` 以上就是在Python更改pip路径的步骤。请注意备份好当前的pip和配置文件,以防止不必要的问题发生。 ### 回答3: 在Python中,pip是一个包管理工具,用于安装、升级和卸载Python包。pip默认安装路径通常是Python安装目录下的Scripts文件夹。 如果需要更改pip安装路径,可以按照以下步骤进行操作: 1. 首先,找到你想要安装pip的目录。可以选择一个新的目录或者现有的目录。 2. 打开命令提示符窗口,并输入`python -m site`,查找Python的site-packages目录。在输出的信息中,找到`sys.path`中标记为site-packages的目录,这就是pip默认安装目录。 3. 复制默认安装目录的完整路径。 4. 打开环境变量设置窗口。在Windows操作系统中,可以通过"控制面板" -> "系统和安全" -> "系统" -> "高级系统设置" -> "环境变量"打开。 5. 在"环境变量"设置窗口中,找到系统变量中的"Path"变量,并点击"编辑"。 6. 在"编辑环境变量"窗口中,找到pip默认安装目录的路径,并将其替换为新的路径。 7. 点击"确定"保存更改,并关闭所有打开的窗口。 现在,你已成功更改pip安装路径。记住,在使用pip时,需要使用新路径来执行pip命令。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值