Куда в linux устанавливается python

Where I should put my python scripts in Linux?

All this files should be available only for root. The main script should run on startup, e.g. via upstart.
Where I should put all this files in Linux filesystem?
What’s the better way for distribution my program?
pip, easy_install, deb, . I haven’t worked with any of these tool, so I want something easy for me. The minimum supported Linux distributive should be Ubuntu.

2 Answers 2

For sure, if this program is to be available only for root , then the main execution python script have to go to /usr/sbin/ .

Config files ought to go to /etc/ , and log files to /var/log/ .

Other python files should be deployed to /usr/share/pyshared/ .

Executable scripts of other languages will go either in /usr/bin/ or /usr/sbin/ depending on whether they should be available to all users, or for root only.

Thanks, but how to make auto location all files in appropriate directories when I give archive with these files to other people? So people who get my program don’t move files by themselves.

Читайте также:  Php удалить директорию файлами

I guess the best option will be to create a .deb package for Ubuntu. You’ll be able to place all files at the locations you want.

If only root should access the scripts, why not put it in /root/ ? Secondly, if you’re going to distribute your application you’ll probably need easy_install or something similar, otherwise just tar.gz the stuff if only a few people will access it?

It all depends on your scale.. Pyglet, wxPython and similar have a hughe userbase.. same for BeautifulSoup but they still tar.gz the stuff and you just use setuptools to deply it (whcih, is another option).

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.27.43548

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

2. Using Python on Unix platforms¶

2.1. Getting and installing the latest version of Python¶

2.1.1. On Linux¶

Python comes preinstalled on most Linux distributions, and is available as a package on all others. However there are certain features you might want to use that are not available on your distro’s package. You can easily compile the latest version of Python from source.

In the event that Python doesn’t come preinstalled and isn’t in the repositories as well, you can easily make packages for your own distro. Have a look at the following links:

2.1.2. On FreeBSD and OpenBSD¶

pkg_add -r python pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages//python-.tgz
pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz

2.1.3. On OpenSolaris¶

You can get Python from OpenCSW. Various versions of Python are available and can be installed with e.g. pkgutil -i python27 .

2.2. Building Python¶

If you want to compile CPython yourself, first thing you should do is get the source. You can download either the latest release’s source or just grab a fresh clone. (If you want to contribute patches, you will need a clone.)

The build process consists of the usual commands:

./configure make make install

Configuration options and caveats for specific Unix platforms are extensively documented in the README.rst file in the root of the Python source tree.

make install can overwrite or masquerade the python3 binary. make altinstall is therefore recommended instead of make install since it only installs exec_prefix /bin/python version .

These are subject to difference depending on local installation conventions; prefix and exec_prefix are installation-dependent and should be interpreted as for GNU software; they may be the same.

For example, on most Linux systems, the default for both is /usr .

Recommended location of the interpreter.

prefix /lib/python version , exec_prefix /lib/python version

Recommended locations of the directories containing the standard modules.

prefix /include/python version , exec_prefix /include/python version

Recommended locations of the directories containing the include files needed for developing Python extensions and embedding the interpreter.

2.4. Miscellaneous¶

To easily use Python scripts on Unix, you need to make them executable, e.g. with

and put an appropriate Shebang line at the top of the script. A good choice is usually

which searches for the Python interpreter in the whole PATH . However, some Unices may not have the env command, so you may need to hardcode /usr/bin/python3 as the interpreter path.

To use shell commands in your Python scripts, look at the subprocess module.

2.5. Custom OpenSSL¶

  1. To use your vendor’s OpenSSL configuration and system trust store, locate the directory with openssl.cnf file or symlink in /etc . On most distribution the file is either in /etc/ssl or /etc/pki/tls . The directory should also contain a cert.pem file and/or a certs directory.
$ find /etc/ -name openssl.cnf -printf "%h\n" /etc/ssl 
$ curl -O https://www.openssl.org/source/openssl-VERSION.tar.gz $ tar xzf openssl-VERSION $ pushd openssl-VERSION $ ./config \ --prefix=/usr/local/custom-openssl \ --libdir=lib \ --openssldir=/etc/ssl $ make -j1 depend $ make -j8 $ make install_sw $ popd 
$ pushd python-3.x.x $ ./configure -C \ --with-openssl=/usr/local/custom-openssl \ --with-openssl-rpath=auto \ --prefix=/usr/local/python-3.x.x $ make -j8 $ make altinstall

Patch releases of OpenSSL have a backwards compatible ABI. You don’t need to recompile Python to update OpenSSL. It’s sufficient to replace the custom OpenSSL installation with a newer version.

Источник

Куда в linux устанавливается python

Для создания программ на Python нам потребуется интерпретатор. Стоит отметить, что в некоторых дистрибутивах Linux (например, в Ubuntu) Python может быть установлен по умолчанию. Для проверки версии Python в терминале надо выполнить следующую команду

Версия интерпретатора Python в Linux

Если Python установлен, то она отобразит версию интерпретатора.

Однако даже если Python установлен, его версия может быть не самой последней. Для установки последней доступной версии Python выполним следующую команду:

sudo apt-get update && sudo apt-get install python3

Если надо установить не последнюю доступную, а какую-то определенную версию, то указывается также подверсия Python. Например, установка версии Python 3.10:

sudo apt-get install python3.10

Соответственно, установка версии Python 3.11:

sudo apt-get install python3.11

Запуск интерпретатора

После установки интерпретатора, как было описано в прошлой теме, мы можем начать создавать приложения на Python. Итак, создадим первую простенькую программу. Для этого введем в терминале

В результате запускается интерпретатор Python. Введем в него следующую строку:

И консоль выведет строку «hello METANIT.COM»:

Первая программа на Python в Linux

Для этой программы использовалась функция print() , которая выводит некоторую строку на консоль.

Создание файла программы

В реальности, как правило, программы определяются во внешних файлах-скриптах и затем передаются интерпретатору на выполнение. Поэтому создадим файл программы. Для этого определим для скриптов папку python . А в этой папке создадим новый текстовый файл, который назовем hello.py . По умолчанию файлы с кодом на языке Python, как правило, имеют расширение py .

Создание скрипта на языке Python на Linux

Откроем этот файл в любом текстовом редакторе и добавим в него следующий код:

name = input("Введите имя: ") print("Привет,", name)

Python в Visual Studio Code

Скрипт состоит из двух строк. Первая строка с помощью функции input() ожидает ввода пользователем своего имени. Введенное имя затем попадает в переменную name .

Вторая строка с помощью функции print() выводит приветствие вместе с введенным именем.

Теперь запустим терминал и с помощью команды cd перейдем к папке, где находится файл с исходным кодом hello.py (например, в моем случае это папка metanit/python в каталоге текущего пользователя). И затем выполним код в hello.py с помощью следующей команды

В итоге программа выведет приглашение к вводу имени, а затем приветствие.

Источник

How to Find the Python Installation Path on Ubuntu, Debian, or Linux Mint

There comes a time now and again when you might want to know where your Python installation path on your Ubuntu, Debian, or Linux Mint distros is located.

Generally, by default, your Python binary is located at /usr/bin/python but it may not always be a guarantee depending on the version you are using. As you can see from this post you can actually install a different version from the default that comes with your distro.

As with the case with many things on Linux systems, there is more than one way to reliably get the Python installation path on that system.

Getting the Python Installation Path Using PYTHONPATH

You can get the value of PYTHONPATH only if it has been set. This is an environment variable that is available on the system. If it has not been set then the result of running any one of the commands below will not return anything.

If the above commands do not work you can also get the path using the which command as shown below.

Conclusion

Once you know the path of the default Python installation path for your system you can permanently add it as an environment variable by opening the startup file you use for your default shell. This is usually ~/.profile in Ubuntu.

Open the file in your preferred editor and add the following line at the end of that file.

You then need to restart your terminal to effect the change. You can also run the above on the command-line if you just need it to last the current session.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Источник

Оцените статью