标签归档:centos

Linux上的两个版本的python。如何使2.7成为默认值

问题:Linux上的两个版本的python。如何使2.7成为默认值

我的linuxbox上有两个版本的python:

$python
Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 


$ /usr/local/bin/python2.7
Python 2.7.3 (default, Oct  8 2013, 15:53:09) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

$ which python
/usr/bin/python
$ ls -al /usr/bin/python
-rwxr-xr-x. 2 root root 4864 Jul 10 22:49 /usr/bin/python

如何将2.7设置为默认版本,以便在键入python时将其置于2.7版本?

I’ve got two versions of python on my linuxbox:

$python
Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 


$ /usr/local/bin/python2.7
Python 2.7.3 (default, Oct  8 2013, 15:53:09) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

$ which python
/usr/bin/python
$ ls -al /usr/bin/python
-rwxr-xr-x. 2 root root 4864 Jul 10 22:49 /usr/bin/python

How can I make 2.7 be the default version so when I type python it puts me in 2.7?


回答 0

您可能实际上不想更改默认的Python。

您的发行版在中安装了标准系统Python /usr/bin,并且可能具有依赖于此脚本的脚本,并由选择#! /usr/bin/env python通常,您可以在2.7中运行Python 2.6脚本,但是您要冒险吗?

最重要的是,闲逛/usr/bin可能会破坏您的包管理器管理包的能力。并且更改目录中的顺序PATH将影响除Python以外的许多其他因素。(实际上,在/usr/local/bin之前更常见/usr/bin,这可能是您真正想要的-但是如果您有其他选择,则可能有充分的理由。)

但是,您无需更改默认的Python即可在键入时使系统运行2.7 python


首先,您可以设置一个shell别名:

alias python=/usr/local/bin/python2.7

在提示符下键入该命令,或者~/.bashrc如果您想使更改持久化,则将其放入您的计算机,现在键入该命令时python将运行您选择的2.7,但是当系统上的某个程序尝试使用/usr/bin/env python标准2.6 运行该脚本时。


或者,只需在2.7(或针对不同项目的单独venv)中创建一个虚拟环境,然后在venv中进行工作。

You probably don’t actually want to change your default Python.

Your distro installed a standard system Python in /usr/bin, and may have scripts that depend on this being present, and selected by #! /usr/bin/env python. You can usually get away with running Python 2.6 scripts in 2.7, but do you want to risk it?

On top of that, monkeying with /usr/bin can break your package manager’s ability to manage packages. And changing the order of directories in your PATH will affect a lot of other things besides Python. (In fact, it’s more common to have /usr/local/bin ahead of /usr/bin, and it may be what you actually want—but if you have it the other way around, presumably there’s a good reason for that.)

But you don’t need to change your default Python to get the system to run 2.7 when you type python.


First, you can set up a shell alias:

alias python=/usr/local/bin/python2.7

Type that at a prompt, or put it in your ~/.bashrc if you want the change to be persistent, and now when you type python it runs your chosen 2.7, but when some program on your system tries to run a script with /usr/bin/env python it runs the standard 2.6.


Alternatively, just create a virtual environment out of your 2.7 (or separate venvs for different projects), and do your work inside the venv.


回答 1

添加/usr/local/bin到您的PATH环境变量中,在列表中早于/usr/bin

通常,这是在您外壳的rc文件中完成的,例如,对于bash,您可以将其放入.bashrc

export PATH="/usr/local/bin:$PATH"

这将导致你的shell先寻找一个python/usr/local/bin,它会与一个之前/usr/bin

(当然,这意味着您还需要/usr/local/bin/python指向python2.7-如果尚未指向,则需要对其进行符号链接。)

Add /usr/local/bin to your PATH environment variable, earlier in the list than /usr/bin.

Generally this is done in your shell’s rc file, e.g. for bash, you’d put this in .bashrc:

export PATH="/usr/local/bin:$PATH"

This will cause your shell to look first for a python in /usr/local/bin, before it goes with the one in /usr/bin.

(Of course, this means you also need to have /usr/local/bin/python point to python2.7 – if it doesn’t already, you’ll need to symlink it.)


回答 2

通过以下方式验证python的当前版本:

$ python --version

然后检查python是指向哪个文件的符号链接。

  $ ll /usr/bin/python

输出示例:

 lrwxrwxrwx 1 root root 9 Jun 16  2014 /usr/bin/python -> python2.7*

检查其他可用的python版本:

$ ls /usr/bin/python*

输出示例:

/usr/bin/python     /usr/bin/python2.7-config  /usr/bin/python3.4         /usr/bin/python3.4m-config  /usr/bin/python3.6m         /usr/bin/python3m
/usr/bin/python2    /usr/bin/python2-config    /usr/bin/python3.4-config  /usr/bin/python3.6          /usr/bin/python3.6m-config  /usr/bin/python3m-config
/usr/bin/python2.7  /usr/bin/python3           /usr/bin/python3.4m        /usr/bin/python3.6-config   /usr/bin/python3-config     /usr/bin/python-config

如果要将python的当前版本更改为3.6版本,请编辑文件〜/ .bashrc:

vim ~/.bashrc

在文件末尾添加以下行并保存:

alias python=/usr/local/bin/python3.6

为python 3.6安装pip

$ sudo apt-get install python3.6 python3.6-dev
$ sudo curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python3.6
$ sudo easy_install pip

成功后,检查pip的当前版本:

$ pip3 -V

输出示例:

pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.6)

Verify current version of python by:

$ python --version

then check python is symbolic link to which file.

  $ ll /usr/bin/python

Output Ex:

 lrwxrwxrwx 1 root root 9 Jun 16  2014 /usr/bin/python -> python2.7*

Check other available versions of python:

$ ls /usr/bin/python*

Output Ex:

/usr/bin/python     /usr/bin/python2.7-config  /usr/bin/python3.4         /usr/bin/python3.4m-config  /usr/bin/python3.6m         /usr/bin/python3m
/usr/bin/python2    /usr/bin/python2-config    /usr/bin/python3.4-config  /usr/bin/python3.6          /usr/bin/python3.6m-config  /usr/bin/python3m-config
/usr/bin/python2.7  /usr/bin/python3           /usr/bin/python3.4m        /usr/bin/python3.6-config   /usr/bin/python3-config     /usr/bin/python-config

If want to change current version of python to 3.6 version edit file ~/.bashrc:

vim ~/.bashrc

add below line in the end of file and save:

alias python=/usr/local/bin/python3.6

To install pip for python 3.6

$ sudo apt-get install python3.6 python3.6-dev
$ sudo curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python3.6
$ sudo easy_install pip

On Success, check current version of pip:

$ pip3 -V

Output Ex:

pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.6)

回答 3

输入命令

which python

//output:
/usr/bin/python

cd /usr/bin
ls -l

在这里你可以看到类似的东西

lrwxrwxrwx 1 root   root            9 Mar  7 17:04  python -> python2.7

您的默认python2.7被软链接到文本’python’

所以删除softlink python

sudo rm -r python

然后重试上面的命令

ls -l

您可以看到该软链接已删除

-rwxr-xr-x 1 root   root      3670448 Nov 12 20:01  python2.7

然后为python3.6创建一个新的软链接

ln -s /usr/bin/python3.6 python

然后python在终端中尝试命令

//output:
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux

类型helpcopyrightcreditslicense了解更多信息。

Enter the command

which python

//output:
/usr/bin/python

cd /usr/bin
ls -l

Here you can see something like this

lrwxrwxrwx 1 root   root            9 Mar  7 17:04  python -> python2.7

your default python2.7 is soft linked to the text ‘python’

So remove the softlink python

sudo rm -r python

then retry the above command

ls -l

you can see the softlink is removed

-rwxr-xr-x 1 root   root      3670448 Nov 12 20:01  python2.7

Then create a new softlink for python3.6

ln -s /usr/bin/python3.6 python

Then try the command python in terminal

//output:
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux

Type help, copyright, credits or license for more information.


回答 4

所有操作系统都带有python的默认版本,并且位于/ usr / bin中。操作系统随附的所有脚本(例如yum)都指向/ usr / bin中驻留的该版本的python。当您想安装新版本的python时,您不想破坏可能不适用于新版本python的现有脚本。

正确的方法是将python安装为替代版本。

e.g.
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 
tar xf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure --prefix=/usr/local/
make && make altinstall

现在,通过执行此操作,现有的脚本(如yum)仍可与/ usr / bin / python一起使用。而您的默认python版本将是/ usr / local / bin中安装的版本。即当您键入python时,您将获得2.7.3

这是因为。$ PATH变量在usr / bin之前具有/ usr / local / bin。

/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

如果python2.7仍然无法作为默认python版本生效,则需要执行此操作

export PATH="/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"

All OS comes with a default version of python and it resides in /usr/bin. All scripts that come with the OS (e.g. yum) point this version of python residing in /usr/bin. When you want to install a new version of python you do not want to break the existing scripts which may not work with new version of python.

The right way of doing this is to install the python as an alternate version.

e.g.
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 
tar xf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure --prefix=/usr/local/
make && make altinstall

Now by doing this the existing scripts like yum still work with /usr/bin/python. and your default python version would be the one installed in /usr/local/bin. i.e. when you type python you would get 2.7.3

This happens because. $PATH variable has /usr/local/bin before usr/bin.

/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

If python2.7 still does not take effect as the default python version you would need to do

export PATH="/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"

回答 5

我想您手动安装了2.7版本,而2.6是从软件包中获得的?

简单的答案是:卸载python软件包。

比较复杂的是:不要在/ usr / local中手动安装。用2.7版本构建软件包,然后升级。

包处理取决于您使用的发行版。

I guess you have installed the 2.7 version manually, while 2.6 comes from a package?

The simple answer is: uninstall python package.

The more complex one is: do not install manually in /usr/local. Build a package with 2.7 version and then upgrade.

Package handling depends on what distribution you use.


bash:mkvirtualenv:找不到命令

问题:bash:mkvirtualenv:找不到命令

按照Doug Hellman的virtualenvwrapper帖子中的说明进行操作,我仍然无法启动测试环境。

[mpenning@tsunami ~]$ mkvirtualenv test
-bash: mkvirtualenv: command not found
[mpenning@tsunami ~]$

请注意,我使用WORKON_HOME的不在我的$HOME。我尝试/usr/local/bin/virtualenvwrapper.shvirtualenvwrapper安装文档中所示进行查找,但是它不存在。

如果这很重要,我正在运行CentOS 6和python 2.6.6。


# File: ~/.bash_profile
# ...

export WORKON_HOME="/opt/virtual_env/"
source "/opt/virtual_env/bin/virtualenvwrapper_bashrc"

After following the instructions on Doug Hellman’s virtualenvwrapper post, I still could not fire up a test environment.

[mpenning@tsunami ~]$ mkvirtualenv test
-bash: mkvirtualenv: command not found
[mpenning@tsunami ~]$

It should be noted that I’m using WORKON_HOME that is not in my $HOME. I tried looking for /usr/local/bin/virtualenvwrapper.sh as shown in the virtualenvwrapper installation docs, but it does not exist.

I’m running CentOS 6 and python 2.6.6, if this matters.


# File: ~/.bash_profile
# ...

export WORKON_HOME="/opt/virtual_env/"
source "/opt/virtual_env/bin/virtualenvwrapper_bashrc"

回答 0

解决方案1

由于某种原因,请virtualenvwrapper.sh安装在中/usr/bin/virtualenvwrapper.sh,而不是在下/usr/local/bin

.bash_profile作品中的以下内容…

source "/usr/bin/virtualenvwrapper.sh"
export WORKON_HOME="/opt/virtual_env/"

我的安装看起来不错,无需采购 virtualenvwrapper_bashrc

解决方案2

或者,如下所述,您可以利用virtualenvwrapper.sh外壳中已经存在的机会,PATH然后发出一个source `which virtualenvwrapper.sh`

Solution 1:

For some reason, virtualenvwrapper.sh installed in /usr/bin/virtualenvwrapper.sh, instead of under /usr/local/bin.

The following in my .bash_profile works…

source "/usr/bin/virtualenvwrapper.sh"
export WORKON_HOME="/opt/virtual_env/"

My install seems to work fine without sourcing virtualenvwrapper_bashrc

Solution 2:

Alternatively as mentioned below, you could leverage the chance that virtualenvwrapper.sh is already in your shell’s PATH and just issue a source `which virtualenvwrapper.sh`


回答 1

尝试:

source `which virtualenvwrapper.sh`

反引号是命令替换-它们将程序打印出的所有内容放入表达式中。在这种情况下,“哪个”检查$ PATH以找到virtualenvwrapper.sh并输出路径。然后,shell通过“源”读取脚本。

如果您希望每次重新启动外壳程序时都会发生这种情况,最好先从“哪个”命令中获取输出,然后将“源代码”行放入外壳程序中,如下所示:

echo "source /path/to/virtualenvwrapper.sh" >> ~/.profile

^这可能因您的外壳而略有不同。另外,请注意不要使用单个>,因为这会截断〜/ .profile:-o

Try:

source `which virtualenvwrapper.sh`

The backticks are command substitution – they take whatever the program prints out and put it in the expression. In this case “which” checks the $PATH to find virtualenvwrapper.sh and outputs the path to it. The script is then read by the shell via ‘source’.

If you want this to happen every time you restart your shell, it’s probably better to grab the output from the “which” command first, and then put the “source” line in your shell, something like this:

echo "source /path/to/virtualenvwrapper.sh" >> ~/.profile

^ This may differ slightly based on your shell. Also, be careful not to use the a single > as this will truncate your ~/.profile :-o


回答 2

我在OS X 10.9.1和python 2.7.5上遇到了相同的问题。没有问题WORKON_HOME的我,但我确实有手动添加source "/usr/local/bin/virtualenvwrapper.sh"~/.bash_profile(或~/.bashrc后我跑UNIX)pip install virtualenvwrapper

I had the same issue on OS X 10.9.1 with python 2.7.5. No issues with WORKON_HOME for me, but I did have to manually add source "/usr/local/bin/virtualenvwrapper.sh" to ~/.bash_profile (or ~/.bashrc in unix) after I ran pip install virtualenvwrapper


回答 3

执行此命令的先决条件-

  1. PIP(递归缩写,P IP nstalls P ackages)是用于安装和管理Python编写的软件包,软件包管理系统。在Python软件包索引(PyPI)中可以找到许多软件包。

    须藤apt-get install python-pip

  2. 安装虚拟环境。用于创建虚拟环境,安装彼此隔离的多个项目的软件包和依赖项。

    sudo pip安装virtualenv

  3. 安装虚拟环境包装器关于虚拟环境包装

    sudo pip安装virtualenvwrapper

安装必备组件后,您需要使虚拟环境包装器生效以创建虚拟环境。以下是步骤-

  1. 在路径变量中设置虚拟环境目录 export WORKON_HOME=(directory you need to save envs)

  2. source /usr/local/bin/virtualenvwrapper.sh -p $WORKON_HOME

如@Mike所提到的,来源`哪个virtualenvwrapper.sh`或which virtualenvwrapper.sh可用于定位virtualenvwrapper.sh文件。

最好在〜/ .bashrc中放置两行,以免每次打开新的Shell时都执行上述命令。这就是使用mkvirtualenv创建环境所需的全部

注意事项-

  • 在Ubuntu下,您可能需要以root用户身份安装virtualenv和virtualenvwrapper。只需在上面的命令前加上sudo前缀即可。
  • 根据用于安装virtualenv的过程,virtualenvwrapper.sh的路径可能会有所不同。通过运行$ find / usr -name virtualenvwrapper.sh查找合适的路径。相应地调整.bash_profile或.bashrc脚本中的行。

Prerequisites to execute this command –

  1. pip (recursive acronym of Pip Installs Packages) is a package management system used to install and manage software packages written in Python. Many packages can be found in the Python Package Index (PyPI).

    sudo apt-get install python-pip

  2. Install Virtual Environment. Used to create virtual environment, to install packages and dependencies of multiple projects isolated from each other.

    sudo pip install virtualenv

  3. Install virtual environment wrapper About virtual env wrapper

    sudo pip install virtualenvwrapper

After Installing prerequisites you need to bring virtual environment wrapper into action to create virtual environment. Following are the steps –

  1. set virtual environment directory in path variable- export WORKON_HOME=(directory you need to save envs)

  2. source /usr/local/bin/virtualenvwrapper.sh -p $WORKON_HOME

As mentioned by @Mike, source `which virtualenvwrapper.sh` or which virtualenvwrapper.sh can used to locate virtualenvwrapper.sh file.

It’s best to put above two lines in ~/.bashrc to avoid executing the above commands every time you open new shell. That’s all you need to create environment using mkvirtualenv

Points to keep in mind –

  • Under Ubuntu, you may need install virtualenv and virtualenvwrapper as root. Simply prefix the command above with sudo.
  • Depending on the process used to install virtualenv, the path to virtualenvwrapper.sh may vary. Find the appropriate path by running $ find /usr -name virtualenvwrapper.sh. Adjust the line in your .bash_profile or .bashrc script accordingly.

回答 4

使用此过程在ubuntu中创建虚拟环境

第1步

安装点子

   sudo apt-get install python-pip

第2步

安装virtualenv

   sudo pip install virtualenv

第三步

创建一个目录来存储您的virtualenvs(我使用〜/ .virtualenvs)

   mkdir ~/.virtualenvs

或使用此命令在env中安装特定版本的python

virtualenv -p /usr/bin/python3.6 venv

第4步

   sudo pip install virtualenvwrapper

第5步

   sudo nano ~/.bashrc

步骤6

在bashrc文件的末尾添加这两行代码

  export WORKON_HOME=~/.virtualenvs
  source /usr/local/bin/virtualenvwrapper.sh

步骤7

打开新终端(推荐)

步骤8

创建一个新的virtualenv

  mkvirtualenv myawesomeproject

步骤9

要在virtualenvs之间加载或切换,请使用workon命令:

  workon myawesomeproject

步骤10

要退出新的virtualenv,请使用

 deactivate

并确保使用pip vs pip3

或按照以下步骤使用python3安装虚拟环境

安装环境

python3 -m venv my-project-env

并使用以下命令激活您的虚拟环境:

source my-project-env/bin/activate

Use this procedure to create virtual env in ubuntu

step 1

Install pip

   sudo apt-get install python-pip

step 2

Install virtualenv

   sudo pip install virtualenv

step 3

Create a dir to store your virtualenvs (I use ~/.virtualenvs)

   mkdir ~/.virtualenvs

or use this command to install specific version of python in env

virtualenv -p /usr/bin/python3.6 venv

step 4

   sudo pip install virtualenvwrapper

step 5

   sudo nano ~/.bashrc

step 6

Add this two line code at the end of the bashrc file

  export WORKON_HOME=~/.virtualenvs
  source /usr/local/bin/virtualenvwrapper.sh

step 7

Open new terminal (recommended)

step 8

Create a new virtualenv

  mkvirtualenv myawesomeproject

step 9

To load or switch between virtualenvs, use the workon command:

  workon myawesomeproject

step 10

To exit your new virtualenv, use

 deactivate

and make sure using pip vs pip3

OR follow the steps below to install virtual environment using python3

Install env

python3 -m venv my-project-env

and activate your virtual environment using the following command:

source my-project-env/bin/activate

回答 5

由于我刚经历了一次阻力,所以我将尝试写两个小时前希望得到的答案。这适用于不只是想要复制粘贴解决方案的人

第一:您是否想知道为什么复制和粘贴路径对某些人有用,而对其他人却无效?**主要原因是,解决方案不同是因为Python版本2.x或3.x不同。实际上,存在与python 2或3一起工作的virtualenv和virtualenvwrapper的不同版本。如果您使用的是python 2,请像这样安装:

sudo pip install virutalenv
sudo pip install virtualenvwrapper

如果您打算使用python 3,请安装相关的python 3版本

sudo pip3 install virtualenv
sudo pip3 install virtualenvwrapper

您已经成功安装了适用于python版本的软件包,并且已经全部安装好吗?好吧,尝试一下。输入workon到你的终端。您的终端将无法找到命令(workon是virtualenvwrapper的命令)。当然不会。Workon是可执行文件,只有在您加载/提供文件后才能使用virtualenvwrapper.sh。但是正式安装指南已经涵盖了这一点,对吧?在文档中说,只需打开.bash_profile并插入以下内容:

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh

尤其是,该命令source /usr/local/bin/virtualenvwrapper.sh似乎很有帮助,因为该命令似乎可以加载/提供所需的文件virtualenvwrapper.sh,该文件包含您要使用的所有命令,如like workonmkvirtualenv但是,是的。按照官方安装指南进行操作时,您很可能会从初始帖子中收到错误消息:mkvirtualenv: command not found。仍然找不到命令,您仍然感到沮丧。那么,这里出了什么问题?问题在于,如果您正在寻找它,则不是virtualenvwrapper.sh。简短提醒…您在这里看:

source /usr/local/bin/virtualenvwrapper.sh

但是,找到所需文件的方法非常简单。只需输入

which virtualenvwrapper

到您的终端。这将在您的PATH中搜索该文件,因为该文件很可能位于系统PATH所包含的某个文件夹中。

如果您的系统非常陌生,则所需的文件将隐藏在PATH文件夹之外。在这种情况下,您可以virtalenvwrapper.sh使用shell命令找到路径find / -name virtualenvwrapper.sh

您的结果可能看起来像这样:/Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenvwrapper.sh 恭喜。You have found your missing file!。现在,您要做的就是更改.bash_profile中的一个命令。只是改变:

source "/usr/local/bin/virtualenvwrapper.sh"

至:

"/Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenvwrapper.sh"

恭喜你 Virtualenvwrapper现在可以在您的系统上运行。但是您可以做一件事来增强您的解决方案。如果virtualenvwrapper.sh使用命令找到了文件,则which virtualenvwrapper.sh知道该文件位于PATH文件夹中。因此,如果只写文件名,则文件系统将假定该文件位于PATH文件夹内。因此,您不必写出完整的路径。只需输入:

source "virtualenvwrapper.sh"

而已。您不再沮丧。您已经解决了问题。希望。

Since I just went though a drag, I’ll try to write the answer I’d have wished for two hours ago. This is for people who don’t just want the copy&paste solution

First: Do you wonder why copying and pasting paths works for some people while it doesn’t work for others?** The main reason, solutions differ are different python versions, 2.x or 3.x. There are actually distinct versions of virtualenv and virtualenvwrapper that work with either python 2 or 3. If you are on python 2 install like so:

sudo pip install virutalenv
sudo pip install virtualenvwrapper

If you are planning to use python 3 install the related python 3 versions

sudo pip3 install virtualenv
sudo pip3 install virtualenvwrapper

You’ve successfully installed the packages for your python version and are all set, right? Well, try it. Type workon into your terminal. Your terminal will not be able to find the command (workon is a command of virtualenvwrapper). Of course it won’t. Workon is an executable that will only be available to you once you load/source the file virtualenvwrapper.sh. But the official installation guide has you covered on this one, right?. Just open your .bash_profile and insert the following, it says in the documentation:

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh

Especially the command source /usr/local/bin/virtualenvwrapper.sh seems helpful since the command seems to load/source the desired file virtualenvwrapper.sh that contains all the commands you want to work with like workon and mkvirtualenv. But yeah, no. When following the official installation guide, you are very likely to receive the error from the initial post: mkvirtualenv: command not found. Still no command is being found and you are still frustrated. So whats the problem here? The problem is that virtualenvwrapper.sh is not were you are looking for it right now. Short reminder … you are looking here:

source /usr/local/bin/virtualenvwrapper.sh

But there is a pretty straight forward way to finding the desired file. Just type

which virtualenvwrapper

to your terminal. This will search your PATH for the file, since it is very likely to be in some folder that is included in the PATH of your system.

If your system is very exotic, the desired file will hide outside of a PATH folder. In that case you can find the path to virtalenvwrapper.sh with the shell command find / -name virtualenvwrapper.sh

Your result may look something like this: /Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenvwrapper.sh Congratulations. You have found your missing file!. Now all you have to do is changing one command in your .bash_profile. Just change:

source "/usr/local/bin/virtualenvwrapper.sh"

to:

"/Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenvwrapper.sh"

Congratulations. Virtualenvwrapper does now work on your system. But you can do one more thing to enhance your solution. If you’ve found the file virtualenvwrapper.sh with the command which virtualenvwrapper.sh you know that it is inside of a folder of the PATH. So if you just write the filename, your file system will assume the file is inside of a PATH folder. So you you don’t have to write out the full path. Just type:

source "virtualenvwrapper.sh"

Thats it. You are no longer frustrated. You have solved your problem. Hopefully.


回答 6

为了virtualenvwrapper在Ubuntu 18.04.3上成功安装,您需要执行以下操作:

  1. 安装 virtualenv

    sudo apt install virtualenv
  2. 安装 virtualenvwrapper

    sudo pip install virtualenv
    sudo pip install virtualenvwrapper
  3. 将以下内容添加到.bashrc文件末尾

    export WORKON_HOME=~/virtualenvs
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
    source ~/.local/bin/virtualenvwrapper.sh
  4. 执行.bashrc文件

    source ~/.bashrc
  5. 创建您的virtualenv

    mkvirtualenv your_virtualenv

In order to successfully install the virtualenvwrapper on Ubuntu 18.04.3 you need to do the following:

  1. Install virtualenv

    sudo apt install virtualenv
    
  2. Install virtualenvwrapper

    sudo pip install virtualenv
    sudo pip install virtualenvwrapper
    
  3. Add the following to the end of the .bashrc file

    export WORKON_HOME=~/virtualenvs
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
    source ~/.local/bin/virtualenvwrapper.sh
    
  4. Execute the .bashrc file

    source ~/.bashrc
    
  5. Create your virtualenv

    mkvirtualenv your_virtualenv
    

回答 7

在Windows 7和Git Bash上,这可以帮助我:

  1. 创建一个〜/ .bashrc文件(在用户主文件夹下)
  2. 添加行导出WORKON_HOME = $ HOME / .virtualenvs(如果此文件夹不存在,则必须创建此文件夹)
  3. 添加行源“ C:\ Program Files(x86)\ Python36-32 \ Scripts \ virtualenvwrapper.sh”(更改virtualenvwrapper.sh的路径)

现在重新启动 git bash和mkvirtualenv命令将可以正常工作。

On Windows 7 and Git Bash this helps me:

  1. Create a ~/.bashrc file (under your user home folder)
  2. Add line export WORKON_HOME=$HOME/.virtualenvs (you must create this folder if it doesn’t exist)
  3. Add line source “C:\Program Files (x86)\Python36-32\Scripts\virtualenvwrapper.sh” (change path for your virtualenvwrapper.sh)

Restart your git bash and mkvirtualenv command now will work nicely.


回答 8

在Windows 10和Windows的Python36上使用Git Bash,我在稍微不同的位置找到了virtualenvwrapper.sh,运行此命令解决了该问题

source virtualenvwrapper.sh 
/c/users/[myUserName]/AppData/Local/Programs/Python36/Scripts

Using Git Bash on Windows 10 and Python36 for Windows I found the virtualenvwrapper.sh in a slightly different place and running this resolved the issue

source virtualenvwrapper.sh 
/c/users/[myUserName]/AppData/Local/Programs/Python36/Scripts

回答 9

通过在〜/ .bash_profile(或unix中的〜/ .bashrc)文件中添加以下两行,解决了我在python 2.7.6的Ubuntu 14.04 OS中的问题。

源“ /usr/local/bin/virtualenvwrapper.sh”

导出WORKON_HOME =“ / opt / virtual_env /”

然后将这两行都执行到终端上。

Solved my issue in Ubuntu 14.04 OS with python 2.7.6, by adding below two lines into ~/.bash_profile (or ~/.bashrc in unix) files.

source “/usr/local/bin/virtualenvwrapper.sh”

export WORKON_HOME=”/opt/virtual_env/”

And then executing both these lines onto the terminal.


回答 10

在Windows 10上,要创建虚拟环境,我将“ pip mkvirtualenv myproject” 替换为“ mkvirtualenv myproject”,并且效果很好。

On Windows 10, to create the virtual environment, I replace “pip mkvirtualenv myproject” by “mkvirtualenv myproject” and that works well.


在NPM安装期间如何使用其他版本的python?

问题:在NPM安装期间如何使用其他版本的python?

我可以通过终端访问运行centos 5.9的VPS,并安装了默认的python 2.4.3。我还通过以下命令安装了python 2.7.3 :(我使用make altinstall代替make install

wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xf Python-2.7.3.tgz
cd Python-2.7.3
./configure
make
make altinstall

然后我通过以下命令从源代码安装了node.js:

python2.7 ./configure
make
make install

问题是,当我使用npm install并尝试安装需要python> 2.4.3的node.js软件包时,出现此错误:

gyp ERR! configure error
gyp ERR! stack Error: Python executable "python" is v2.4.3, which is not supported by gyp.
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.
gyp ERR! stack     at failPythonVersion (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:125:14)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:114:9

我应该如何“通过–python开关以指向Python> = v2.5.0”

I have terminal access to a VPS running centos 5.9 and default python 2.4.3 installed. I also installed python 2.7.3 via these commands: (I used make altinstall instead of make install)

wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -xf Python-2.7.3.tgz
cd Python-2.7.3
./configure
make
make altinstall

then I installed node.js from source via these commands:

python2.7 ./configure
make
make install

The problem is, when I use npm install and try to install a node.js package which requires python > 2.4.3 I get this error:

gyp ERR! configure error
gyp ERR! stack Error: Python executable "python" is v2.4.3, which is not supported by gyp.
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.
gyp ERR! stack     at failPythonVersion (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:125:14)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:114:9

how should I “pass the –python switch to point to Python >= v2.5.0”?


回答 0

您可以使用--pythonnpm选项,如下所示:

npm install --python=python2.7

或将其设置为始终使用:

npm config set python python2.7

Npm会在需要时依次将此选项传递给node-gyp。

(注意:我是在Github上发布一个问题将此文档包含在文档中的人,因为对此有太多问题;-))

You can use --python option to npm like so:

npm install --python=python2.7

or set it to be used always:

npm config set python python2.7

Npm will in turn pass this option to node-gyp when needed.

(note: I’m the one who opened an issue on Github to have this included in the docs, as there were so many questions about it ;-) )


回答 1

在运行npm install之前将python设置为python2.7

Linux:

export PYTHON=python2.7

视窗:

set PYTHON=python2.7

set python to python2.7 before running npm install

Linux:

export PYTHON=python2.7

Windows:

set PYTHON=python2.7

回答 2

对于Windows用户,类似这样的方法应该起作用:

PS C:\angular> npm install --python=C:\Python27\python.exe

For Windows users something like this should work:

PS C:\angular> npm install --python=C:\Python27\python.exe

回答 3

好的,所以您已经找到了解决方案。只想分享对我有用很多次的东西;

我创建了setpy2别名,可以帮助我切换python。

alias setpy2="mkdir -p /tmp/bin; ln -s `which python2.7` /tmp/bin/python; export PATH=/tmp/bin:$PATH"

执行setpy2之前运行npm install。该开关将一直有效,直到您退出终端为止,之后python将其设置回系统默认值。

您也可以将这种技术用于任何其他命令/工具。

Ok, so you’ve found a solution already. Just wanted to share what has been useful to me so many times;

I have created setpy2 alias which helps me switch python.

alias setpy2="mkdir -p /tmp/bin; ln -s `which python2.7` /tmp/bin/python; export PATH=/tmp/bin:$PATH"

Execute setpy2 before you run npm install. The switch stays in effect until you quit the terminal, afterwards python is set back to system default.

You can make use of this technique for any other command/tool as well.


回答 4

为了快速使用它,npm install –python =“ c:\ python27”

for quick one time use this works, npm install –python=”c:\python27″


回答 5

如果您在路径上没有python或想指定目录,此方法效果更好:

//for Windows
npm config set python C:\Python27\python.exe

//for Linux
npm config set python /usr/bin/python27

This one works better if you don’t have the python on path or want to specify the directory :

//for Windows
npm config set python C:\Python27\python.exe

//for Linux
npm config set python /usr/bin/python27

pip install-locale.Error:不支持的语言环境设置

问题:pip install-locale.Error:不支持的语言环境设置

完整的堆栈跟踪:

  ~ pip install virtualenv
Traceback (most recent call last):
  File "/usr/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python3.4/site-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib64/python3.4/locale.py", line 592, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

在同一台服务器上,我成功运行pip install virtualenv了python2.7.x。

现在,我刚刚使用安装了python3.4 curl https://bootstrap.pypa.io/get-pip.py | python3.4

  ~ pip --version
pip 8.1.1 from /usr/lib/python3.4/site-packages (python 3.4)

pip uninstall virtualenv 也会引发相同的错误

Full stacktrace:

➜  ~ pip install virtualenv
Traceback (most recent call last):
  File "/usr/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python3.4/site-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib64/python3.4/locale.py", line 592, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

On the same server, I successfully ran pip install virtualenv with python 2.7.x.

Now, I’ve just installed python3.4 using curl https://bootstrap.pypa.io/get-pip.py | python3.4.

➜  ~ pip --version
pip 8.1.1 from /usr/lib/python3.4/site-packages (python 3.4)

pip uninstall virtualenv throws the same error too


回答 0

根本原因是:您的环境变量LC_ALL丢失或以某种方式无效

简短答案-

只需运行以下命令:

$ export LC_ALL=C

如果在新的终端窗口中仍然出现错误,请在.bashrc文件底部添加错误。

长答案-

这是我的locale设置:

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C

Python2.7

    $ uname -a
    Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 GNU/Linux
    $ python --version
    Python 2.7.9
    $ pip --version
    pip 8.1.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
    $ unset LC_ALL
    $ pip install virtualenv
    Traceback (most recent call last):
      File "/usr/local/bin/pip", line 11, in <module>
        sys.exit(main())
      File "/usr/local/lib/python2.7/dist-packages/pip/__init__.py", line 215, in main
        locale.setlocale(locale.LC_ALL, '')
      File "/usr/lib/python2.7/locale.py", line 579, in setlocale
        return _setlocale(category, locale)
    locale.Error: unsupported locale setting
    $ export LC_ALL=C
    $ pip install virtualenv
    Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python2.7/dist-packages

The root cause is: your environment variable LC_ALL is missing or invalid somehow

Short answer-

just run the following command:

$ export LC_ALL=C

If you keep getting the error in new terminal windows, add it at the bottom of your .bashrc file.

Long answer-

Here is my locale settings:

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C

Python2.7

    $ uname -a
    Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 GNU/Linux
    $ python --version
    Python 2.7.9
    $ pip --version
    pip 8.1.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
    $ unset LC_ALL
    $ pip install virtualenv
    Traceback (most recent call last):
      File "/usr/local/bin/pip", line 11, in <module>
        sys.exit(main())
      File "/usr/local/lib/python2.7/dist-packages/pip/__init__.py", line 215, in main
        locale.setlocale(locale.LC_ALL, '')
      File "/usr/lib/python2.7/locale.py", line 579, in setlocale
        return _setlocale(category, locale)
    locale.Error: unsupported locale setting
    $ export LC_ALL=C
    $ pip install virtualenv
    Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python2.7/dist-packages

回答 1

运行以下命令(它将起作用):

export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales

Run the following command (it will work):

export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales

回答 2

有人可能会觉得有用。您可以将这些语言环境设置放在.bashrc文件中,该文件通常位于主目录中。
只需在.bashrc中添加此命令:
export LC_ALL=C
然后键入source .bashrc
Now,例如,当您通过ssh连接时,您无需每次都手动调用此命令。

Someone may find it useful. You could put those locale settings in .bashrc file, which usually located in the home directory.
Just add this command in .bashrc:
export LC_ALL=C
then type source .bashrc
Now you don’t need to call this command manually every time, when you connecting via ssh for example.


回答 3

尽管可以设置导出环境变量的语言环境,但每次启动会话时都必须这样做。以这种方式设置语言环境将永久解决问题:

sudo apt-get install locales
sudo locale-gen en_US.UTF-8
sudo echo "LANG=en_US.UTF-8" > /etc/default/locale

While you can set the locale exporting an env variable, you will have to do that every time you start a session. Setting a locale this way will solve the problem permanently:

sudo apt-get install locales
sudo locale-gen en_US.UTF-8
sudo echo "LANG=en_US.UTF-8" > /etc/default/locale

回答 4

[此答案仅适用于linux平台]

您应该知道的第一件事是,大多数语言环境配置文件的定位路径都可以从localedef --help以下位置获取:

$ localedef --help | tail -n 5
System's directory for character maps : /usr/share/i18n/charmaps
                       repertoire maps: /usr/share/i18n/repertoiremaps
                       locale path    : /usr/lib/locale:/usr/share/i18n
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>

看到最后一个/usr/share/i18n?这是您的xx_XX.UTF-8配置文件所在的位置:

$ ls /usr/share/i18n/locales/zh_*
/usr/share/i18n/locales/zh_CN  /usr/share/i18n/locales/zh_HK  /usr/share/i18n/locales/zh_SG  /usr/share/i18n/locales/zh_TW

怎么办 ?我们需要将它们编译为存档二进制文件。一种方式,例如假设我有/usr/share/i18n/locales/en_LOVE,我可以将其添加到编译列表(即/etc/locale-gen文件)中:

$ tail -1 /etc/locale.gen 
en_LOVE.UTF-8 UTF-8

并将其编译为二进制sudo locale-gen

$ sudo locale-gen 
Generating locales (this might take a while)...
  en_AG.UTF-8... done
  en_AU.UTF-8... done
  en_BW.UTF-8... done
  ...
  en_LOVE.UTF-8... done
Generation complete.

且以期望现在更新系统默认的语言环境LANGLC_ALL…等与此update-locale

sudo update-locale LANG=en_LOVE.UTF-8

update-locale实际上还意味着更新此/etc/default/locale文件,该文件将在登录时由系统提供以设置环境变量:

$ head /etc/default/locale 
#  File generated by update-locale
LANG=en_LOVE.UTF-8
LC_NUMERIC="en_US.UTF-8"
...

但是我们可能不想重启才能生效,因此我们可以将其来源到当前shell会话中的环境变量:

$ . /etc/default/locale

怎么sudo dpkg-reconfigure locales样 如果您玩转它,您将知道此命令基本上充当GUI来简化上述步骤,即Edit /etc/locale.gen-> sudo locale-gen->sudo update-locale LANG=en_LOVE.UTF-8

对于python,只要/etc/locale.gen包含该语言环境候选者并locale.gen进行编译,就setlocale(category, locale)可以正常运行locale.Error: unsupoorted locale setting。您可以通过观察文件来检查要在中设置的正确字符串en_US.UTF-8/ ,然后取消注释并根据需要对其进行编译。该文件中不带点的表示正确的字符串是和。en_US/....etcsetlocale()/etc/locale.genzh_CN GB2312zh_CNzh_CN.GB2312

[This answer is target on linux platform only]

The first thing you should know is most of the locale config file located path can be get from localedef --help :

$ localedef --help | tail -n 5
System's directory for character maps : /usr/share/i18n/charmaps
                       repertoire maps: /usr/share/i18n/repertoiremaps
                       locale path    : /usr/lib/locale:/usr/share/i18n
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>

See the last /usr/share/i18n ? This is where your xx_XX.UTF-8 config file located:

$ ls /usr/share/i18n/locales/zh_*
/usr/share/i18n/locales/zh_CN  /usr/share/i18n/locales/zh_HK  /usr/share/i18n/locales/zh_SG  /usr/share/i18n/locales/zh_TW

Now what ? We need to compile them into archive binary. One of the way, e.g. assume I have /usr/share/i18n/locales/en_LOVE, I can add it into compile list, i.e. /etc/locale-gen file:

$ tail -1 /etc/locale.gen 
en_LOVE.UTF-8 UTF-8

And compile it to binary with sudo locale-gen:

$ sudo locale-gen 
Generating locales (this might take a while)...
  en_AG.UTF-8... done
  en_AU.UTF-8... done
  en_BW.UTF-8... done
  ...
  en_LOVE.UTF-8... done
Generation complete.

And now update the system default locale with desired LANG, LC_ALL …etc with this update-locale:

sudo update-locale LANG=en_LOVE.UTF-8

update-locale actually also means to update this /etc/default/locale file which will source by system on login to setup environment variables:

$ head /etc/default/locale 
#  File generated by update-locale
LANG=en_LOVE.UTF-8
LC_NUMERIC="en_US.UTF-8"
...

But we may not want to reboot to take effect, so we can just source it to environment variable in current shell session:

$ . /etc/default/locale

How about sudo dpkg-reconfigure locales ? If you play around it you will know this command basically act as GUI to simplify the above steps, i.e. Edit /etc/locale.gen -> sudo locale-gen -> sudo update-locale LANG=en_LOVE.UTF-8

For python, as long as /etc/locale.gen contains that locale candidate and locale.gen get compiled, setlocale(category, locale) should work without throws locale.Error: unsupoorted locale setting. You can check the correct string en_US.UTF-8/en_US/....etc to be set in setlocale(), by observing /etc/locale.gen file, and then uncomment and compile it as desired. zh_CN GB2312 without dot in that file means the correct string is zh_CN and zh_CN.GB2312.


回答 5

对于Dockerfile,这对我有用:

RUN locale-gen en_US.UTF-8  
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8  

如何安装locale-gen?

docker ubuntu / bin / sh:1:locale-gen:找不到

For Dockerfile, this works for me:

RUN locale-gen en_US.UTF-8  
ENV LANG en_US.UTF-8  
ENV LANGUAGE en_US:en  
ENV LC_ALL en_US.UTF-8  

How to install locale-gen?

docker ubuntu /bin/sh: 1: locale-gen: not found


回答 6

我有同样的问题,对我没有用"export LC_ALL=c"

尝试export LC_ALL="en_US.UTF-8"(它将起作用)。

I had the same problem, and "export LC_ALL=c" didn’t work for me.

Try export LC_ALL="en_US.UTF-8" (it will work).


回答 7

该错误消息表示语言环境设置有问题。要解决此问题(如其他答案所示),您需要修改语言环境。

在Mac OS X Sierra上,我发现最好的方法是~/bash_profile按如下所示修改文件:

export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"

除非您使用以下命令重新加载bash配置文件,否则此更改在当前cli会话中不会立即显现source ~/.bash_profile

这个答案非常接近我发布给其他非相同,非重复的问题(即与pipenv不相关)的答案,但是碰巧需要相同的解决方案。

致主持人:尊敬;由于这个原因,我以前的答案被删除了,但是我觉得这有点愚蠢,因为实际上,无论何时只要错误是“语言环境问题”,这个答案都适用…但是可能会触发多种不同的情况,语言和环境该错误。

因此,A)将问题标记为重复项是没有意义的,而B)调整答案也没有意义,因为解决方法非常简单,在每种情况下都是相同的,并且无法从修饰中受益。

The error message indicates a problem with the locale setting. To fix this as indicated by other answers you need to modify your locale.

On Mac OS X Sierra I found that the best way to do this was to modify the ~/bash_profile file as follows:

export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"

This change will not be immediately evident in your current cli session unless you reload the bash profile by using: source ~/.bash_profile.

This answer is pretty close to answers that I’ve posted to other non-identical, non-duplicate questions (i.e. not related to pipenv) but which happen to require the same solution.

To the moderator: With respect; my previous answer got deleted for this reason but I feel that was a bit silly because really this answer applies almost whenever the error is “problem with locale”… but there are a number of differing situations, languages, and environments which could trigger that error.

Thus it A) doesn’t make sense to mark the questions as duplicates and B) doesn’t make sense to tailor the answer either because the fix is very simple, is the same in each case and does not benefit from ornamentation.


回答 8

Ubuntu:

$ sudo vi /etc/default/locale

在文件末尾添加以下设置。

LC_ALL = en_US.UTF-8

Ubuntu:

$ sudo vi /etc/default/locale

Add below setting at the end of file.

LC_ALL = en_US.UTF-8