标签: pyenv

Pyenv 指向正确的版本“python”但不是“python3”

我使用的是Ubuntu 20.04,所以我的Python系统版本是3.8.5。我已经使用 pyenv 安装了 Python 3.9.1,并设置了特定于文件夹的 python,如下所示:

$ pyenv local 3.9.1
$ cat .python-version
3.9.1
Run Code Online (Sandbox Code Playgroud)

Pyenv 的垫片存在并在 $PATH 中可用:

$ which python
/home/username/.pyenv/shims/python
$ which python3
/home/username/.pyenv/shims/python3
Run Code Online (Sandbox Code Playgroud)

Pyenv 本身可以正确识别我要使用的版本:

$ pyenv which python
/home/username/.pyenv/versions/3.9.1/bin/python
$ pyenv which python3
/home/username/.pyenv/versions/3.9.1/bin/python3
Run Code Online (Sandbox Code Playgroud)

但是,当我运行python或时python3,只有前者给我正确的版本,而python3恢复到系统版本:

$ python --version
Python 3.9.1
$ python3 --version
Python 3.8.5
Run Code Online (Sandbox Code Playgroud)

可能是什么问题呢?我使用其自己的安装程序( https://pyenv.run中的脚本)安装了 pyenv,并且我的 .bashrc 按照说明包含以下行:

export PATH="/home/username/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Run Code Online (Sandbox Code Playgroud)

python ubuntu python-3.x pyenv

5
推荐指数
1
解决办法
1671
查看次数

错误“无法初始化 virtualenvwrapper。” (WSL Windows 10)

介绍

在Windows 10 上的WSL(Wsman Shell 命令行,版本 0.2.1)中,我安装了pyenv并尝试使用pyenv-virtualenvwrapper。然而,我似乎无法启动并运行它,即使使用与我的 Ubuntu PC 相同的配置文件.bashr也是如此。.profile

接下来,我将描述我所做的尝试。

检查 pyenv

username@hd1pcms0347:~$ pyenv
pyenv 1.2.26
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   --version   Display the version of pyenv
   activate    Activate virtual environment
   commands    List all available pyenv commands
   deactivate   Deactivate virtual environment
   exec        Run an executable with the selected Python version
   global      Set or show the global Python version(s)
   help        Display help for a command
   hooks       List …
Run Code Online (Sandbox Code Playgroud)

python virtualenvwrapper pyenv windows-subsystem-for-linux pyenv-virtualenv

5
推荐指数
1
解决办法
2152
查看次数

使用 pyenv 安装 python 3.8 时出现问题

我尝试使用命令 pyenv install 3.8.11 安装 python

如果您需要更多信息,请告诉我。谢谢您的关注。输出:

构建失败(Ubuntu 20.04 使用 python-build 20180424)

Inspect or clean up the working tree at /tmp/python-build.20210821132713.23441
Results logged to /tmp/python-build.20210821132713.23441.log

Last 10 log lines:
  File "/tmp/python-build.20210821132713.23441/Python-3.8.11/Lib/ensurepip/__init__.py", line 206, in _main
    return _bootstrap(
  File "/tmp/python-build.20210821132713.23441/Python-3.8.11/Lib/ensurepip/__init__.py", line 125, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/tmp/python-build.20210821132713.23441/Python-3.8.11/Lib/ensurepip/__init__.py", line 34, in _run_pip
    return subprocess.run([sys.executable, "-c", code], check=True).returncode
  File "/tmp/python-build.20210821132713.23441/Python-3.8.11/Lib/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/tmp/python-build.20210821132713.23441/Python-3.8.11/python', '-c', '\nimport runpy\nimport sys\nsys.path = …
Run Code Online (Sandbox Code Playgroud)

python ubuntu pyenv

5
推荐指数
1
解决办法
4614
查看次数

如何在bash脚本中激活pyenv创建的virtualenv?

我需要编写一个脚本来启动使用 pyenv 开发的gunicorn + django 站点,该脚本类似于

#!/bin/bash
                                                                                
pyenv activate .ve
pyenv exec gunicorn config.wsgi:application --name mini2 --workers 8 \
--workers 8 --bind=unix:/tmp/run/mini2.socket \
--log-level=debug --log-file=-
Run Code Online (Sandbox Code Playgroud)

和错误消息

2021-12-06 14:09:00 [mini2@s017 mini2]$ ./prodution.sh 

Failed to activate virtualenv.

Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.

2021-12-06 14:09:55 [mini2@s017 mini2]$ 
Run Code Online (Sandbox Code Playgroud)

我可以逐行运行脚本。所以脚本中肯定有问题,但我不知道出了什么问题。

我已经在 bashrc 中附加了几行关于 pyenv 的内容

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
 eval "$(pyenv init -)"
fi
Run Code Online (Sandbox Code Playgroud)

那么有没有办法在bash脚本中激活pyenv创建的virtualenv?有什么建议 ?? …

python bash pyenv

5
推荐指数
2
解决办法
6430
查看次数

在 macOS - 12.0 M1 (arm64) 中使用 pyenv 安装 python 3.5.10 时出现问题

尝试使用以下命令安装 python 3.5.10,

LDFLAGS="-L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" arch -x86_64 pyenv install --patch 3.5.10 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
Run Code Online (Sandbox Code Playgroud)

错误

python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.5.10.tar.xz...
-> https://www.python.org/ftp/python/3.5.10/Python-3.5.10.tar.xz
Installing Python-3.5.10...
patching file Misc/NEWS.d/next/macOS/2020-06-24-13-51-57.bpo-41100.mcHdc5.rst
patching file configure
Hunk #1 succeeded at 3492 (offset 66 lines).
patching file configure.ac
Hunk #1 succeeded at 492 (offset -18 lines).
python-build: use tcl-tk from $PYTHON_CONFIGURE_OPTS
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
WARNING: The Python …
Run Code Online (Sandbox Code Playgroud)

python pyenv apple-m1 macos-monterey

5
推荐指数
1
解决办法
2010
查看次数

在操作系统 12.3+ 的新 macbook pro M1 上使用 pyenv 安装 python 3.7.6 时出错

我正在努力使用 pyenv 在运行 mac os 12.3.1 的新 macbook pro M1 上安装 python 版本 3.7.6。

我的配置

$ clang -v
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Run Code Online (Sandbox Code Playgroud)
$ pyenv install 3.7.6

python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.6.tar.xz...
-> https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz
Installing Python-3.7.6...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 12.3.1 using python-build 2.2.5-10-g58427b9a)

Inspect or clean up the working …
Run Code Online (Sandbox Code Playgroud)

python macos pyenv apple-m1

5
推荐指数
1
解决办法
8632
查看次数

使用 pyenv 安装 Python 3.11.1 的问题

我尝试使用 Pyenv 安装 Python 3.11.1 并得到以下结果:

\n
\xe2\x9e\x9c  ~ pyenv install 3.11.1 \nDownloading Python-3.11.1.tar.xz...\n-> https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tar.xz\nInstalling Python-3.11.1...\nTraceback (most recent call last):\n  File "<string>", line 1, in <module>\n  File "/home/eustignos/.pyenv/versions/3.11.1/lib/python3.11/ssl.py", line 100, in <module>\n    import _ssl             # if we can't import it, let the error propagate\n    ^^^^^^^^^^^\nModuleNotFoundError: No module named '_ssl'\nERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?\n\nPlease consult to the Wiki page to fix the problem.\nhttps://github.com/pyenv/pyenv/wiki/Common-build-problems\n\n\nBUILD FAILED (Ubuntu 22.10 using python-build 20180424)\n\nInspect or clean up the working …
Run Code Online (Sandbox Code Playgroud)

python ubuntu homebrew openssl pyenv

5
推荐指数
1
解决办法
1万
查看次数

如何从正在运行的脚本中判断正在运行的Python解释器?

我想在我的脚本中输出运行它的Python解释器的完整路径:

#!/usr/bin/env python

print("{}".format(full_path_of_interpreter_running_this_script)
Run Code Online (Sandbox Code Playgroud)

该脚本位于中PATH,运行方式为:

script.py
Run Code Online (Sandbox Code Playgroud)

我可以那样做吗?怎么样?

注意:执行which pythontype python进行bash操作无济于事,因为我正在使用pyenv,并且pyenv正在执行垫片魔术。

注意:除了识别Python可执行文件之外,我还对识别正在使用的virtualenv感兴趣,并且我认为了解解释器的完整路径将对此有所帮助。

python pyenv

4
推荐指数
1
解决办法
421
查看次数

在circleci中使用Python 3.6.0

我正在使用python 3.6启动新项目,我想将circleci附加到我的项目中.

我的circle.yml是

machine:
  timezone:
    Asia/Seoul

  python:
    version: 3.6.0

dependencies:
  pre:
    - pip install -r requirements/ci.txt

test:
  post:
    - python manage.py test
Run Code Online (Sandbox Code Playgroud)

和circleci错误

python-build: definition not found: 3.6.0

The following versions contain `3.6.0' in the name:
  3.6.0b1

See all available versions with `pyenv install --list'.

If the version you need is missing, try upgrading pyenv:

  cd /opt/circleci/.pyenv/plugins/python-build/../.. && git pull && cd -

((if (or (= "3.6.0" "system") (pyenv versions --bare | grep -x -q "'3.6.0'")) (pyenv global "3.6.0") (chain-and …
Run Code Online (Sandbox Code Playgroud)

python integration circleci pyenv python-3.6

4
推荐指数
1
解决办法
1358
查看次数

Pipenv没有认识到Pyenv版本?

我安装了Python 3.7.0,但对于特定的Django项目,我想使用Python 3.6.5.使用pyenv此目的,在我的MacBook Pro我跑brew install pyenv,其次pyenv install 3.6.5,在项目的根目录下,pyenv local 3.6.5.我已经验证Python版本3.6.5是活动的:

Kurts-MacBook-Pro-2:lucy-web kurtpeek$ cat .python-version
3.6.5
Kurts-MacBook-Pro-2:lucy-web kurtpeek$ pyenv versions
  system
* 3.6.5 (set by /Users/kurtpeek/Documents/dev/lucy2/lucy-web/.python-version)
Run Code Online (Sandbox Code Playgroud)

Pipfile我使用的是类似以下内容:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.6.5"
Run Code Online (Sandbox Code Playgroud)

但是,当我运行时pipenv shell,我得到它'默认'到我的系统版本,python 3.7.0:

Kurts-MacBook-Pro-2:lucy-web kurtpeek$ pipenv shell
Loading .env environment variables...
Warning: Your Pipfile requires python_version 3.6.5, but you are using 3.7.0 (/Users/k/.local/share/v/l/bin/python).
  $ …
Run Code Online (Sandbox Code Playgroud)

python pyenv pipenv

4
推荐指数
1
解决办法
2233
查看次数