venv 不创建激活脚本 python3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26215790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:13:16  来源:igfitidea点击:

venv doesn't create activate script python3

pythonubuntupython-3.xvirtualenvpython-venv

提问by sayth

When trying to create a virtulenv using venv with python 3 on ubuntu it isn't creating an activate script. It conitunally exits with an error 1.

当尝试在 ubuntu 上使用 venv 和 python 3 创建 virtulenv 时,它不会创建激活脚本。它以错误 1 ​​连续退出。

Following docs and other posts on SO such as https://stackoverflow.com/a/19848770

关注 SO 上的文档和其他帖子,例如https://stackoverflow.com/a/19848770

I have tried creating it 2 different ways.

我试过用 2 种不同的方式创建它。

sayth@sayth-TravelMate-5740G:~/scripts$ python3 -m venv test4
Error: Command '['/home/sayth/scripts/test4/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
sayth@sayth-TravelMate-5740G:~/scripts$ source test4/bin/activate
bash: test4/bin/activate: No such file or directory
sayth@sayth-TravelMate-5740G:~/scripts$ ls test4/bin/
python  python3

or

或者

sayth@sayth-TravelMate-5740G:~/scripts$ pyvenv-3.4 test5
Error: Command '['/home/sayth/scripts/test5/bin/python3.4', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
sayth@sayth-TravelMate-5740G:~/scripts$ ls test5/bin/
python  python3  python3.4

How can I get it to fully create a venv?

我怎样才能让它完全创建一个venv?

If I do it as below with stil no success unsure what the issue is?

如果我按照下面的方法做仍然没有成功不确定问题是什么?

sayth@sayth-TravelMate-5740G:~/scripts$ python3 -Im venv panda3
Error: Command '['/home/sayth/scripts/panda3/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
sayth@sayth-TravelMate-5740G:~/scripts$ python3 -m venv panda4
Error: Command '['/home/sayth/scripts/panda4/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

采纳答案by ChillarAnand

Looks like you are using Ubuntu 14.04. It was shipped with a brokenpyvenv. There is a simple work around to create venv using Python 3

看起来您正在使用Ubuntu 14.04. 它带有一个破损的pyvenv. 有一个简单的工作来创建 venv 使用Python 3

1. Create venv without pip

1. 不用pip创建venv

python3 -m venv --without-pip test4

or

或者

pyvenv-3.4 --without-pip test4

2. Get pip in your env

2. 在你的环境中获取 pip

source test4/bin/activate
curl https://bootstrap.pypa.io/get-pip.py | python
deactivate
source test4/bin/activate

or

或者

pyvenv-3.4 --without-pip myvenv
source ./myvenv/bin/activate
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-3.4.4.tar.gz
tar -vzxf setuptools-3.4.4.tar.gz
cd setuptools-3.4.4
python setup.py install
cd ..
wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz
tar -vzxf pip-1.5.6.tar.gz
cd pip-1.5.6
python setup.py install
cd ..
deactivate
source ./myvenv/bin/activate

Source: HackerNews, AskUbuntu

来源:黑客新闻AskUbuntu

回答by KenBlend

This worked for me:

这对我有用:

python3 -m venv --without-pip test4

Once I typed that in the terminal, the "test4" venv was created. And the 'activate' script was also created in the 'bin' directory.

一旦我在终端中输入,就创建了“test4”venv。并且在 'bin' 目录中也创建了 'activate' 脚本。

To anyone using python3, having trouble with this, just substitute the name of the directory you want to create for "test4" (or rename it later).

对于任何使用 python3 的人,遇到这个问题,只需将要创建的目录的名称替换为“test4”(或稍后重命名)。

That should do it.

应该这样做。

回答by Jimmy Olano

Anaconda involucred.

蟒蛇卷入。

If you are usingAnacondaorMinicondathis solution may help:

如果您使用的是AnacondaMiniconda,此解决方案可能会有所帮助:

Conda manages python itself as a package, so that conda update python is possible, in contrast to pip, which only manages Python packages. Conda is available in Anaconda and Miniconda (an easy-to-install download with just Python and conda).

Conda 将python 本身作为一个包来管理,这样conda 更新python 是可能的,而pip 只管理Python 包。Conda 在 Anaconda 和 Miniconda 中可用(只需 Python 和 conda 即可轻松安装下载)。

So, this command would help:

所以,这个命令会有所帮助:

conda update python

very disturbing for me but well, hands to the keyboard in a terminal window:(click here, see the picture)

对我来说非常令人不安,但好吧,在终端窗口中将手放在键盘上:(单击此处,查看图片)

Thanks for your attention, have a nice day!

感谢您的关注,祝您有美好的一天!

回答by Rory

The command:

命令:

python3 -m virtualenv env

works for me, whereas:

对我有用,而:

python3 -m venv env

does not.

才不是。