我最近需要一个项目的 Python3 更新版本,所以我从源代码构建它;我相信我把事情搞得一团糟。所有基于 apt 的操作现在都以错误结束:
(Reading database ... 320897 files and directories currently installed.)
Removing nvidia-prime (0.6.2) ...
Traceback (most recent call last):
File "/usr/bin/lsb_release", line 28, in <module>
import lsb_release
ImportError: No module named 'lsb_release'
dpkg: error processing package nvidia-prime (--remove):
subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
nvidia-prime
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)
我相信 nvidia 错误与其说是问题,不如说是一种症状。这是在我尝试添加源时发现的,并遇到了:
sudo: add-apt-repository: command not found
Run Code Online (Sandbox Code Playgroud)
我很乐意将此框升级到 14.10,但所有基于升级的命令都返回相同的 lsb_release 消息。关于恢复我的包管理能力有什么建议吗?
编辑:使用 python 路径信息更新 …
我想保留该功能,但将 的位置更改~/.python_history为$XDG_DATA_HOME/python/python_history。
这给了我以下想法:我可以创建$XDG_CONFIG_HOME/python/pythonrc并指向$PYTHONSTARTUP它。在那里我想替换函数readline.read_history_file,readline.write_history_file和readline.append_history_file.
有没有办法用自己替换这些函数,包含自定义filename参数?
如果没有,您还有其他想法如何解决这个问题吗?
当使用 来安装任何东西时pip,它会无限期地挂起,例如(正在运行pip install geoclue2 -v):
Using pip 21.0.1 from /usr/lib/python3.9/site-packages/pip (python 3.9)
Defaulting to user installation because normal site-packages is not writeable
Created temporary directory: /tmp/pip-ephem-wheel-cache-ujsolamd
Created temporary directory: /tmp/pip-req-tracker-d3dddja9
Initialized build tracking at /tmp/pip-req-tracker-d3dddja9
Created build tracker: /tmp/pip-req-tracker-d3dddja9
Entered build tracker: /tmp/pip-req-tracker-d3dddja9
Created temporary directory: /tmp/pip-install-kl5q0ihq
1 location(s) to search for versions of geoclue2:
* https://pypi.org/simple/geoclue2/
Fetching project page and analyzing links: https://pypi.org/simple/geoclue2/
Getting page https://pypi.org/simple/geoclue2/
Found index url https://pypi.org/simple
Getting credentials from keyring for …Run Code Online (Sandbox Code Playgroud) 我使用以下命令安装了最新的 Python 3.10:
sudo apt install python3.10
Run Code Online (Sandbox Code Playgroud)
但无法使用它。
当我运行相同的命令时,得到这个
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'postgresql-plpython3-10' for regex 'python3.10'
postgresql-plpython3-10 is already the newest version (10.19-0ubuntu0.18.04.1)
Run Code Online (Sandbox Code Playgroud)
请帮助我如何查找和使用已安装的 Python。
我已经在 Ubuntu 上安装了 python 3.10。现在我有两个版本:3.8 和 3.10。我想将 Python 3.10 设置为默认值。我遵循了这里的建议:Change the Python3 default version in Ubuntu
ls /usr/bin/python*
/usr/bin/python3 /usr/bin/python3.8-config /usr/bin/python3-pasteurize
/usr/bin/python3.10 /usr/bin/python3-config
/usr/bin/python3.8 /usr/bin/python3-futurize
Run Code Online (Sandbox Code Playgroud)
我尝试设置 get python3.10 优先级 1 和 python3.8 优先级 2:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
Run Code Online (Sandbox Code Playgroud)
我可以使用以下方法检查它:
sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.8 2 auto mode
* 1 /usr/bin/python3.10 1 manual mode …Run Code Online (Sandbox Code Playgroud) 在 Python 3 中,有没有办法找出系统使用的语言?
即使是一个棘手的一个,虽然,这样的:从文件中读取偷偷摸摸目录,并找到字符串'ENG'或'FRE'文件的内容中...
yml 文件中的一些代码:
- name: --- run /opt/installer/bin/install.sh ---
expect:
command: /opt/installer/bin/install.sh
responses:
'Are you installing the application at the central data center? [yes/no default: yes]? [yes]': "\n"
'What is the code of central data center [default: 01]? [01]': "\n"
'What is ip or hostname of your server [default: localhost]? [localhost]': 'portal'
Run Code Online (Sandbox Code Playgroud)
我pexpect 3.3在两台服务器(ansible和目标machines)上都安装了模块。
[root@portal pexpect-3.3]# python setup.py install
running install
running build
running build_py
running install_lib
running install_egg_info
Removing /usr/lib/python2.7/site-packages/pexpect-3.3-py2.7.egg-info
Writing /usr/lib/python2.7/site-packages/pexpect-3.3-py2.7.egg-info
Run Code Online (Sandbox Code Playgroud)
当我运行 playbook …
我只是在我的家庭实验室中使用 RHEL 的免费版本,因此没有 Red Hat 的支持。CentOS 的相同修复应适用于此处...
\n我什至不应该尝试升级 Python3,但事后看来(一如既往)20/20。这是我尝试使用 YUM 时得到的结果:
\n[root@RHEL7 ~]# yum update\n-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory\n[root@RHEL7 ~]# yum\n-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory\nRun Code Online (Sandbox Code Playgroud)\n通过阅读有关此错误的信息,我似乎必须完全重新安装 Python2 和/或 3,但我想知道是否还有其他修复方法。Python2 和 Python3 实际上仍然可以正常工作(至少在 REPL 中):
\n[root@RHEL7 ~]# python3\nPython 3.6.8 (default, Aug 13 2020, 07:46:32)\n[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux\nType "help", "copyright", "credits" or "license" for more information.\n>>>\n[root@RHEL7 ~]# python2\nPython 2.7.5 (default, Aug 13 2020, 02:51:10)\n[GCC …Run Code Online (Sandbox Code Playgroud) 我有以下 docker 文件,基本映像 rundeckpro/runner:latest; 它没有安装Python。镜像构建后,有两个版本的python:python3.10和python3.11,尽管我只请求了python3.11。这有什么原因吗?我可以避免这种情况吗?
ARG RUNNER_VERSION=latest
FROM rundeckpro/runner:${RUNNER_VERSION}
ARG PYTHON_VERSION=python3.11
ARG DEBIAN_FRONTEND=noninteractive
USER root
RUN apt-get update && \
apt-get install -y --no-install-recommends software-properties-common && \
apt-get install -y --no-install-recommends gpg-agent && \
add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get install -y --no-install-recommends $PYTHON_VERSION && \
apt-get install -y --no-install-recommends $PYTHON_VERSION-venv && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
USER runner
Run Code Online (Sandbox Code Playgroud) 我通常使用apt包管理器安装早期版本(3.11.2),并从源手动安装更高版本(3.12)。当我像这样执行 python 脚本时:
./python_script.py
Run Code Online (Sandbox Code Playgroud)
该脚本使用较早的版本而不是较新的版本。出于可移植性的原因,我想将默认的 shebang 行#!/usr/bin/env python3单独保留在脚本的开头。
这是一个示例测试脚本。
#!/usr/bin/env python3
import sys
def main():
print(sys.version)
main()
Run Code Online (Sandbox Code Playgroud)
编辑:通过上述配置,我认为目前最快的解决方案(可能不是最好的,因为未来的后果,请参阅下面社区的详细解释的答案和评论)是更改 / 中 python3 符号链接的目标/usr/local/bin/python3.12的/usr/local/bin/python3.12 的替代品,其中存储了我的 python3.12 二进制文件。
编辑2:如第二个屏幕截图所示,./myscript.py通过验证该目录位于环境变量中的目录/usr/local/bin之前并将二进制文件重命名为./usr/binPATHpython3.12/usr/local/bin/python3