Install Python 3 on Cloudready/Chromium/Chrome OS without installing Linux containers/environments

这一生的挚爱 提交于 2020-12-23 12:56:33

问题


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).

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 / $

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,

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.

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

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?


回答1:


There can be 2 possibilities:

1). The python3.6 is already installed.

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

To check that try:

which python3 or simply try running python3.

2). uninstalling python2 so that the merge will not even be necessary can also help you out.




回答2:


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.

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).

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

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).

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

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

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

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.

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

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.

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.

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

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



来源:https://stackoverflow.com/questions/63991488/install-python-3-on-cloudready-chromium-chrome-os-without-installing-linux-conta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!