简体   繁体   English

如何在预装python但没有root特权的Linux上安装Tkinter?

[英]How to install Tkinter on linux with preinstalled python but without root privilege?

Since on most linux distributions tkinter comes in a different package I have difficulties installing it on my university computer, where we don't have root access. 由于大多数Linux发行版中的tkinter都带有不同的软件包,因此我很难在没有root用户访问权限的大学计算机上安装它。

I get the following error: 我收到以下错误:

/usr/bin/python3: Error while finding spec for 'tkinter.__main__' (<class 'ImportError'>: 
No module named '_tkinter', please install the python3-tk package);

I have found this answer: https://stackoverflow.com/a/10015546/2898702 Then I compiled and deployed TCL and TK in /home/<user>/.local However the last step python setup.py build seems to expect, that the python interpreter is also installed in a user directory, which is not the case for me. 我已经找到了这个答案: https : //stackoverflow.com/a/10015546/2898702然后我在/home/<user>/.local编译并部署了TCL和TK。但是, python setup.py build的最后一步似乎是可以预期的, python解释器也安装在用户目录中,对我而言不是这种情况。

Is there a way to install TCL and TK without also installing the python interpreter locally? 有没有一种方法可以安装TCL和TK,而无需在本地也安装python解释器? Preferably using pip or easy_install. 最好使用pip或easy_install。

In case it is relevant, the distribution seems to be linux mint. 如果相关,发行版似乎是linux mint。 Uname -a gives me: Linux pc404 4.4.0-59-generic #80~14.04.1-Ubuntu SMP Fri Jan 6 18:02:23 UTC 2017 i686 i686 i686 GNU/Linux Uname -a给我: Linux pc404 4.4.0-59-generic #80~14.04.1-Ubuntu SMP Fri Jan 6 18:02:23 UTC 2017 i686 i686 i686 GNU/Linux

For day to day working with Python, even in unrestricted environments, the way to go is to use "virtualenv", which creates a new Python environment in a user controlled folder, and you are then able to install any Python packages you want, regardless of what is available for the system. 对于使用Python的日常工作,即使在不受限制的环境中,也要使用“ virtualenv”,它会在用户控制的文件夹中创建一个新的Python环境,然后您就可以安装所需的任何Python软件包,而无论系统可用的内容。 Since you have a working compiler environment, that works for almost everything. 由于您拥有一个正常的编译器环境,因此几乎适用于所有环境。

However, tkinter itself is not available for pip install, since it is expected to come along core Python stdlib (it is about time Linux distributions would stop the idea of leaving it out - it is not like the 5MB maximum it uses would make a difference, when compared to the harm it does by not being there by default. Even customizing the Python package and creating the new one is likely more effort than it saves from anyone). 但是,tkinter本身不适用于pip安装,因为它有望随核心Python stdlib一起出现(现在Linux发行版本将停止将其遗弃的想法-这不像它使用的最大5MB大小会有所作为) ,与危害相比,它默认情况下不存在。即使自定义Python程序包并创建新程序包,也可能比从任何人节省下来的工作量更多。

Anyway, you might try building Python in your local directory - if the system has a compiler, it probably would just work: download the tar.gz source from python.org, uncompress it and just do " ./configure --prefix=/home/user/python36 " . 无论如何,您都可以尝试在本地目录中构建Python-如果系统具有编译器,则可能就可以了:从python.org下载tar.gz源,解压缩并执行“ ./configure --prefix=/home/user/python36 “。 Now even when that works, it is nice to use virtualenvs for your projects. 现在,即使可行,也可以在项目中使用virtualenvs。

Otherwise, you should try to find a pre-compiled Python for the specific Linux distribution, or, see in the instuctions for your package manager, if you can install Python and other packages in a different system root directory, under your control. 否则,您应该尝试查找针对特定Linux发行版的预编译Python,或者,如果可以在控制下将Python和其他软件包安装在其他系统根目录中,请参见软件包管理器的说明。

Anther alternative, if you have another Linux you have control, build it to a USB stick, and at the University lab, just use the ln command to link it to whatever was the target directory where you built it - that would work as a portable stick. 另外,如果您拥有另一个可以控制的Linux,可以将其构建到USB记忆棒中,然后在大学实验室中,只需使用ln命令将其链接到构建它的目标目录中即可,这可作为便携式计算机使用。棒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM