User Tools

Site Tools


python3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python3 [2017/02/05 11:57] – [Debian based distros] dblumepython3 [2023/04/14 20:37] (current) dblume
Line 1: Line 1:
 ====== Python3 ====== ====== Python3 ======
  
-If I want Python 3.6, I have to compile it myself.  Use "dnf" for RedHat based distros and "apt-get" for Debian.+If I want Python 3.7, I have to compile it myself.  Use "dnf" for RedHat based distros and "apt-get" for Debian.
  
 ===== RedHat based distros ===== ===== RedHat based distros =====
Line 11: Line 11:
 </code> </code>
  
-Then on Fedora and macOS...+Then on Fedora and CentOS...
  
 <code bash> <code bash>
-wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz +wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz 
-tar -xvf Python-3.6.0.tgz +tar -xvf Python-3.7.0.tgz 
-cd Python-3.6.0/ +cd Python-3.7.0/ 
-./configure --prefix=/opt/python3+./configure --prefix=/usr/local/bin/python3.7 --enable-optimizations
 make make
 sudo make install sudo make install
-# sudo ln -s /opt/python3/bin/python3 /usr/bin/python3+# sudo ln -s /usr/local/bin/python3.7/bin/python3 /usr/bin/python3
 </code> </code>
  
-===== Debian based distros =====+On my dev system at work, I seem to have configured a prefix like /opt/python3. Then when CentOS updates itself, it changes a symbolic link in /usr/bin/python3 
 + 
 +    sudo rm /usr/bin/python3 && sudo ln -s /opt/python3/bin/python3 /usr/bin/python3 
 + 
 +For **OS X**, brew upgrading httpie seems to upgrade to the latest Python 3, so I didn't have to do stuff. 
 + 
 +===== Debian based distros (Start) =====
  
 For Debian (eg., Rasbian) try [[http://www.unixmen.com/howto-install-python-3-x-in-ubuntu-debian-fedora-centos/|the following]] (on raspberry pi libssl-dev isn't available): For Debian (eg., Rasbian) try [[http://www.unixmen.com/howto-install-python-3-x-in-ubuntu-debian-fedora-centos/|the following]] (on raspberry pi libssl-dev isn't available):
  
 <code bash> <code bash>
-sudo apt-get install build-essential libncursesw5-dev libreadline-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev+sudo apt-get install build-essential libncursesw5-dev libreadline-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev libffi-dev
 </code> </code>
 +
 +==== (Aside) OpenSSL 1.0.1 issue in Raspbian ====
 +
 +On Raspbian Jessie the make command (below) may have output that looks like this:
  
 <code> <code>
Line 36: Line 46:
 </code> </code>
  
-On Raspbian, I put it in the default location:+On Raspbian, the pip module may not work because it relies on the ssl module. 
 + 
 +<code> 
 +pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 
 +</code> 
 + 
 +Python's setup.py explains: 
 + 
 +> Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host(). 
 + 
 +If you check the version of ssh: 
 + 
 +<code> 
 +$ openssl version 
 +OpenSSL 1.0.1t  3 May 2016 
 +</code> 
 + 
 +That OpenSSL is too old. So you may have to [[https://raspberrypi.stackexchange.com/questions/66782/how-to-install-openssl-1-0-2-on-raspberry-pi3/67045|make your own OpenSSL library]].
  
 <code bash> <code bash>
-cd Python-3.6.0/ +# Add the backport apt source. 
-./configure+echo "deb-src http://httpredir.debian.org/debian jessie-backports main contrib non-free" | \ 
 +      sudo tee /etc/apt/sources.list.d/jessie-backports.list 
 +sudo apt update 
 + 
 +# Get the openssl source 
 +apt-get source openssl/jessie-backports 
 + 
 +# Make and install it. 
 +cd openssl-1.0.2k
 +./config --prefix=/usr
 make make
 +make test
 sudo make install sudo make install
 +</code>
 +
 +**Update**: The following apt-cache policy command showed the old libssl was still installed. It's probably bad, but I [[https://my-take-on.tk/2018/09/10/installing-latest-python-3x-and-pip-on-any-debian-based-system/|installed the new one with apt install -t jessie-backports]].
 +
 +<code>
 +sudo apt-cache policy libssl-dev
 +</code>
 +
 +===== Debian based distros (Continued) =====
 +
 +Then, back to Python3, on Raspbian, I put it in the default location, /usr/local:
 +
 +<code bash>
 +screen  # Because using optimizations will take hours
 +cd Python-3.7.0/
 +./configure --enable-optimizations
 +make -j4
 +sudo make install
 +[[ $TERM != "screen" ]] || exit  # exit if in screen session
 +</code>
 +
 +===== Modules =====
 +
 +Sometimes I have trouble with pip3 (ImportError: cannot import name 'main' from 'pip'), so prefer to use "python3 -m pip" instead.
 +
 +<code bash>
 +sudo -H python3 -m pip install --upgrade pip
 +sudo -H python3 -m pip install requests
 +sudo -H python3 -m pip install numpy
 +sudo -H python3 -m pip install matplotlib
 +python3 -m pip install --user --upgrade httpie
 +</code>
 +
 +===== Weird hack for impyla =====
 +
 +Refers to https://stackoverflow.com/questions/43918993/python-buildpack-fatal-error-sasl-sasl-h-no-such-file-or-directory
 +
 +<code bash>
 +sudo python3 -m pip install --no-deps impyla
 +sudo python3 -m pip install --no-deps git+https://github.com/snowch/thrift_sasl
 +# sudo python3 -m pip install thriftpy
 +</code>
 +
 +===== MatPlotLib =====
 +
 +There's another note on MatPlotLib over at my [[wsl]] page. For the first time on a Macintosh, I had to set the MatPlotLib backend to 'MacOSX'. Otherwise the plot window would appear but not draw any lines.
 +
 +<code python>
 +import matplotlib
 +matplotlib.use('MacOSX')
 </code> </code>
python3.1486324670.txt.gz · Last modified: 2023/04/12 20:44 (external edit)