在 Cloudready/Chromium/Chrome OS 上安装 Python 3,无需安装 Linux 容器/环境 [英] Install Python 3 on Cloudready/Chromium/Chrome OS without installing Linux containers/environments

查看:125
本文介绍了在 Cloudready/Chromium/Chrome OS 上安装 Python 3,无需安装 Linux 容器/环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我在 VirtualBox 6.1 上安装了 Neverware 的 Chromium OS 版本,称为 Cloudready,为 Chromebook 开发 Python 应用程序.此版本的 Chromium OS 是 48.0.2564.116 开发人员版本(由于图形不兼容,不会安装较新的版本).由于我没有 Google 帐户,因此我以访客用户身份登录 Chromium OS(不知何故,我以访客身份拥有管理权限,这对我的开发目的有好处).

Recently I installed Neverware's version of Chromium OS, called Cloudready, on VirtualBox 6.1, to develop Python apps for Chromebooks. This version of Chromium OS is 48.0.2564.116 developer build (newer versions won't install due to graphics incompatibilities). As I do not have a Google Account, I login into Chromium OS as Guest user (somehow I have administrative powers as Guest, which is good for my developmental purposes).

我发现预装了 Python 2.7.3.我尝试安装 Python 3.6,为此,我尝试找到预装的包管理器,最终我找到了它.预装的包管理器 (portage) 不会安装任何东西,因为它会给出与此类似的错误:

I found that Python 2.7.3 was preinstalled. I tried to install Python 3.6, and to do so, I tried to find the preinstalled package manager, which I eventually found. The package manager that is preinstalled (portage), doesn't install anything, because it gives errors similar to this one:

chronos@localhost / $ sudo emerge dev-lang/python:3.6
!!! PORTAGE_BINHOST unset, but use is requested.
!!! Problem with sandbox library. Disabling...

Calculating dependencies... done!

WARNING: A requested package will not be merged because it is listed in
package.provided:

  dev-lang/python:3.6 pulled in by 'args'

>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.
chronos@localhost / $

我尝试通过 get-pip.py 脚本为 Python 2 安装 Python PIP="nofollow noreferrer">这里,它奏效了.因为我想为 Chromebook 的程序创建图形界面,所以我想安装 tkinter 模块,因为我不希望我的程序的用户必须使用终端来执行我的 Python程序并安装 Python 模块,我想安装 PyInstaller.我想通过 PIP 安装 PyInstaller,但是 PIP 会在尝试安装任何模块时抛出以下错误:

I tried installing Python PIP for Python 2 from the get-pip.py script provided here, and it worked. Because I want to create graphical interfaces for my programs for Chromebooks, I wanted to install the tkinter module, and because I didn't want the users of my programs to have to use the Terminal to execute my Python programs and install Python modules, I wanted to install PyInstaller. I wanted to install PyInstaller through PIP, but PIP throws the following error for any attempted module installation:

/usr/local/lib64/python2.7/site-packages/pip/_vendor/urllib3/util/ssl_.py:387: SNIMissingWarning: An HTTPS requ
est has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. Thi
s may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can up
grade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/l
atest/advanced-usage.html#ssl.warnings
  SNIMissingWarning,
/usr/local/lib64/python2.7/site-packages/pip_vendor/urllib3/util/ssl_.py:142: InsecurePlatformWarning: A true
SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause cert
ain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information,
see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecurePlatformWarning,

在尝试安装 PyInstaller 时,PIP 实际上设法收集了 pyinstaller-4.0.tar.gz 包,但在安装时失败,因为 PyInstaller 安装程序引发异常/错误 BackendUnavailable,然后 PIP 再次引发 InsecurePlatformWarning 错误.正如@BryanOakley 所指出的,我无法从 PIP 安装 Tkinter,我在使用 Chromium OS 时忘记了这一点(例如,在 Ubuntu 上安装 Tkinter 的命令是 sudo apt-get install python3-tk),这让事情变得更加棘手.

When trying to install PyInstaller, PIP actually managed to collect the pyinstaller-4.0.tar.gz package, but it fails upon installation because the PyInstaller installer raises an exception/error BackendUnavailable, and then PIP raises the InsecurePlatformWarning error again. As pointed out by @BryanOakley, I cannot install Tkinter from PIP, which I forgot while I was using Chromium OS (for example, the command to install Tkinter on Ubuntu is sudo apt-get install python3-tk), which makes things even trickier.

从引发的错误来看,我似乎必须安装更新版本的 Python(我已经尝试过,但无济于事).我尝试通过安装 Anaconda 3 和 Miniconda 3 来安装 Python 3,但两者都提供相同的错误,我什至查看了 Stack Overflow 以及人们投票为 answer 仍然对我不起作用.以下命令...

From the errors raised, it appears that I have to install a newer version of Python (which I have already tried, to no avail). I tried to install Python 3 by installing Anaconda 3 and then Miniconda 3, but both provide the same error, and I have even looked through Stack Overflow and what people had voted as the answer still did not work for me. The following commands...

$ mkdir ~/Downloads/TMP
$ TMPDIR=~/Downloads/TMP sudo bash ~/Downloads/Miniconda3-latest-Linux-x86_64.sh -p /usr/local/miniconda3

...最终导致此输出:

...eventually result in this output:

/usr/local/miniconda3/conda.exe: error while loading shared libraries: libz.so.1: failed to segment from sh
ared object: Operation not permitted
/usr/local/miniconda3/conda.exe: error while loading shared libraries: libz.so.1: failed to segment from sh
ared object: Operation not permitted

到目前为止没有任何效果.如何在不安装 Linux 容器/环境(例如安装官方 Linux(测试版)或 Crouton)或从 Google Play 商店安装任何内容的情况下,在 Chromium OS 版本 48 上成功安装带有 Tkinter 和 PyInstaller 的 Python 3.6?

Nothing has worked thus far. How can I successfully install Python 3.6 with Tkinter and PyInstaller on Chromium OS Version 48 without installing Linux containers/environments (such as the option to install the official Linux (Beta) or Crouton) or installing anything from the Google Play Store?

推荐答案

解释为什么 Miniconda 不安装的答案是正确的,/tmp 安装为 noexec(安装时没有可执行权限).不幸的是,他们建议的修复方法(指定不同的 TMPDIR 安装目录)对我不起作用.但是,我最终设法找到了不同的方法.

The answer that explains why Miniconda doesn't install was correct that /tmp is mounted as noexec (mounted with no executable permission). Unfortunately, their suggested approach to fix it (specify a different TMPDIR directory for installation) did not work for me. However, I eventually managed to find a different approach.

因此,重启 Chromebook 并进入开发者模式.打开 Crosh(Chrome Developer Shell)并输入命令 shell 以访问隐藏的Bash shell(因为我使用的是 Chromium OS 开发者版本,而不是 Chrome OS,所以我不需要进入开发者模式来访问 Bash shell).

So, reboot the Chromebook and enter Developer Mode. Open the Crosh (Chrome Developer Shell) and type in the command shell to access the hidden Bash shell (as I am using Chromium OS developer build, not Chrome OS, I do not need to enter a developer mode to access the Bash shell).

现在,不要像我之前引用的答案中所建议的那样指定不同的 TMPDIR 目录,而是将 tmp 重新挂载为 exec(使用可执行权限):

Now, instead of specifying a different TMPDIR directory as suggested in the answer I've referenced earlier, remount tmp as exec (with executable permission):

sudo mount /tmp -o remount,exec

当提示输入密码时,输入用户 chronos 的密码.chronos 有(显然)几种不同的默认密码,包括 facepunchpasswordchromelocalhosttest0000 和空白密码(无).就我而言,它是 chrome.如果您使用的是官方 Chromebook 并已启动到开发者模式,则您应该在启用开发者模式时使用 chromeos-setdevpasswd 设置密码(有关更多信息,请单击 此处).

When prompted for a password, type in the password for user chronos. There are (apparently) several different default passwords for chronos, including facepunch, password, chrome, localhost, test0000, and a blank password (nothing). In my case it was chrome. If you are using an official Chromebook and have booted into Developer Mode, you should have set a password with chromeos-setdevpasswd when enabling Developer Mode (for more information click here).

之后,从 Conda 网站(不过记得下载64位版本),将工作目录更改为下载的Miniconda安装脚本文件所在的位置,运行它,并将安装位置更改为具有写入权限的位置(在我的情况下为/usr/local/conda3).

After that, download the Miniconda installation script for Linux from the Conda website (remember to download the 64-bit version though), change the working directory to the location of the downloaded Miniconda installation script file, run it, and change the install location to a location with write privileges (in my case /usr/local/conda3).

cd ~/Downloads
sudo bash ~/Downloads/Miniconda3-latest-Linux-x86_64.sh -p /usr/local/conda3

安装完成后,您必须将 Conda 安装添加到 PATH:

When installation finishes, you must add your Conda installation to PATH:

echo "PATH=/usr/local/conda3/bin:$PATH" >> ~/.bashrc

重启Crosh,再次进入Bash shell.使用 echo $PATH 验证已安装的 Conda 二进制文件的目录是否在 PATH 中,如果 /usr/local/conda3/bin 在 PATH 中,请验证 Python 是否已安装python3 --version.

Restart the Crosh and enter the Bash shell again. Verify that the directory of the installed Conda binaries is in PATH with echo $PATH and if /usr/local/conda3/bin is in PATH, verify that Python is installed with python3 --version.

现在是安装其他模块的时候了.Miniconda 的安装包括包管理器 Conda,它专门安装 Python 包(但是,Conda 中还有一些其他包可用,例如 GCC).使用 Conda,您可以安装 Tkinter、PyInstaller 和许多其他 Python 包:

Now it is time to install other modules. The installation of Miniconda includes the package manager Conda which specifically installs Python packages (however, there are some other packages available in Conda, such as GCC). Using Conda, you can install Tkinter, PyInstaller, and many other Python packages:

conda install -c anaconda tk
conda install -c anaconda pyinstaller

安装 PyInstaller 有效,但在 Chromium OS 上似乎没有 objcopy 之类的工具,这意味着 PyInstaller 无法编译任何 Python 脚本,并且如 PyInstaller 要求中所述,lddobjcopyobjdump 必须安装,PyInstaller 才能在 Linux 安装上工作.解决方法是在另一台 Linux 计算机上使用 PyInstaller 编译 Python 脚本,然后在 Chrome/Chromium OS 上运行编译后的脚本.

Installing PyInstaller works, but it appears that on Chromium OS, there is no such tool as objcopy, meaning that PyInstaller cannot compile any Python scripts, and, as explained in the PyInstaller requirements, ldd, objcopy, and objdump must be installed for PyInstaller to work on Linux installations. The workaround for this is to compile Python scripts with PyInstaller on another Linux computer and then run the compiled script on Chrome/Chromium OS.

此外,在较新版本的 Chromium OS 上,图形 Python 应用程序(使用 Tkinter、PyQt 等制作)无法运行,因为它们无法识别系统 DISPLAY 环境变量.问题在于 Chrome/Chromium 操作系统的整个图形显示由 Google Chrome 网络浏览器程序控制,并且网络浏览器在没有 DISPLAY 变量的情况下运行,这意味着用户在操作系统中启动的任何 GUI 程序(意味着它将由 Chrome 浏览器启动)将不带 DISPLAY 变量.

Also, on newer versions of Chromium OS, graphical Python applications (made with Tkinter, PyQt, etc.) don't run because they don't recognise the system DISPLAY environment variable. The problem is that the entire graphical display of Chrome/Chromium OS is controlled by the Google Chrome web browser program and the web browser runs with no DISPLAY variable, meaning that any GUI program started in the OS by the user (meaning that it would be started by the Chrome browser) would start with no DISPLAY variable.

解决方法是为 Chrome 浏览器设置 DISPLAY 变量.为此,您需要使用命令 sudo su 以 root 身份登录,因为 Crosh 不允许编辑您需要编辑的文件,即使使用 sudo 命令.使用 sudo su 以 root 身份登录后,您需要运行以下命令:

The workaround is to set the DISPLAY variable for the Chrome browser. To do this, you will need to login as root with the command sudo su, as Crosh does not allow editing the file you will need to edit, even with the sudo command. After logging in as root with sudo su, you will need to run the following commands:

mount -o remount,rw /dev/root /
echo "DISPLAY=:0" >> /etc/chrome_dev.conf

然后重新启动,现在您应该能够运行图形 Python 程序以及控制台 Python 程序了.

Then reboot, and now you should be able to run graphical Python programs as well as console Python programs.

这篇关于在 Cloudready/Chromium/Chrome OS 上安装 Python 3,无需安装 Linux 容器/环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆