Python: Difference between revisions
NickPGSmith (talk | contribs)  | 
				NickPGSmith (talk | contribs) No edit summary  | 
				||
| (19 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== PIP ==  | == PIP ==  | ||
On Windows pip may not be installed globally, so add to the PATH:  | |||
* C:\Users\jbloggs\AppData\Roaming\Python\Python313\Scripts  | |||
On Windows, start pip with:  | On Windows, start pip with:  | ||
  py -m pip  |   py -m pip  | ||
See also [https://packaging.python.org/en/latest/tutorials/installing-packages/ here].  | |||
== Python Compilation ==  | |||
 dnf groupinstall 'Development Tools'  | |||
 dnf install python3-devel libffi-devel  | |||
 wget https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tar.xz  | |||
 tar xvf Python-3.12.2.tar.xz  | |||
 ./configure --enable-shared --enable-optimizations --with-ensurepip=install  | |||
 make  | |||
 sudo make altinstall  | |||
Altinstall does not execute bininstall and maninstall, so good for not overwriting system python. Test resultant binary:  | |||
 /usr/local/bin/python3.12 --version  | |||
If you want somewhere else than /usr/local, add --prefix=/opt or similarto configure. Optionally:  | |||
  make test  | |||
Add the binary directory (eg /usr/local/bin) to the PATH. Add the library to the path, eg add /usr/local/lib to /etc/ld.so.conf/local.conf, then run:  | |||
 ldconfig  | |||
== Virtual Environments ==  | == Virtual Environments ==  | ||
| Line 13: | Line 38: | ||
or Linux:  | or Linux:  | ||
  . py-env/demo/bin/activate  | |||
Install within a venv:  | Install within a venv:  | ||
  python -m pip install   |  pip install --upgrade pip  | ||
 python -m pip install pyinstaller  | |||
 python -m pip install requests  | |||
Optionally, force a specific version, such as:  | |||
  python -m pip install requests==2.30.0  | |||
Ensure shared libraries are accessible, eg:  | |||
 export LD_LIBRARY_PATH=/usr/local/lib  | |||
Deactivate an env:  | Deactivate an env:  | ||
  deactivate  |   deactivate  | ||
== Python Installer ==  | == Python Installer ==  | ||
Latest revision as of 12:26, 14 January 2025
PIP
On Windows pip may not be installed globally, so add to the PATH:
- C:\Users\jbloggs\AppData\Roaming\Python\Python313\Scripts
 
On Windows, start pip with:
py -m pip
See also here.
Python Compilation
dnf groupinstall 'Development Tools' dnf install python3-devel libffi-devel wget https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tar.xz tar xvf Python-3.12.2.tar.xz
./configure --enable-shared --enable-optimizations --with-ensurepip=install make sudo make altinstall
Altinstall does not execute bininstall and maninstall, so good for not overwriting system python. Test resultant binary:
/usr/local/bin/python3.12 --version
If you want somewhere else than /usr/local, add --prefix=/opt or similarto configure. Optionally:
make test
Add the binary directory (eg /usr/local/bin) to the PATH. Add the library to the path, eg add /usr/local/lib to /etc/ld.so.conf/local.conf, then run:
ldconfig
Virtual Environments
Create a virtual environment:
python -m venv py-env/demo
Activate a virtual environment on Windows:
py-env\demo\Scripts\activate
or Linux:
. py-env/demo/bin/activate
Install within a venv:
pip install --upgrade pip python -m pip install pyinstaller python -m pip install requests
Optionally, force a specific version, such as:
python -m pip install requests==2.30.0
Ensure shared libraries are accessible, eg:
export LD_LIBRARY_PATH=/usr/local/lib
Deactivate an env:
deactivate
Python Installer
pip install pyinstaller
Add C:\Users\<user>\AppData\Roaming\Python\Python312\Scripts to PATH:
pyinstaller --onefile file.py
and the resultant executable will be in the dist directory.