I cross-compile Python3.5.5 on a Ubuntu12 virtual machine. Then I transfer the project to an industrial controller. The Python interpreter generally works. But there is a problem with the ssl module. When I try to import this module, I get the message:

>>> import math >>> import ssl Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.5/ssl.py", line 99, in <module> import _ssl # if we can't import it, let the error propagate ImportError: No module named '_ssl' >>> 

Returned to the virtual machine and compiled Openssl for ARM. I used the instruction here on this link - https://assil.me/2017/09/30/cross-compile-openssl-arm-zynq.html . I think what happened, because the file openssl command displays a message:

 openssl: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, BuildID[sha1]=0xf6d37a7af0fb5f9cedb9cf8ddaafbf5f60022129, not stripped 

Here's what to do next? Where and what should I register in Configure when cross-compiling Python3.5.5?

3 answers 3

Team

 >>> import ssl 

it is not performed during cross-compilation, but at the moment when you already started python (on ARM - I guess?) and entered it from the keyboard to the invitation of the python interpreter.

Therefore, the process of cross-compilation has nothing to do with it - it is left behind. But error message

 ImportError: No module named '_ssl' 

says that the python interpreter that issued it cannot find the ssl module in the system libraries. The _ssl file is the flag signaling that this module is installed in the system.

The standard way to install this module is to execute the command

 pip instsll ssl 

pip: python installer program. However, in order for pip to work on your ARM normally, three conditions must be met.

  1. Must be installed pip itself.
  2. Your ARM must be connected to the Internet.
  3. pip must be configured correctly for your network environment. In the sense - could reach the repository of the Python modules.

If all this is - no problem.

    There is only a compiler, we also need binary versions of libraries. It seems to me ./configure configured a python without ssl support.

    Try

     dpkg --add-architecture arm apt update apt build-dep python3:arm 

    And reassemble the python. Although I would take the already collected from the repository if you do not need any options.

    • I collect these commands without ssl. Powered by the controller then Python. Just there was a need to import ssl. I think there is no need for your teams. Maybe I'm not catching up with (little experience)? - Rashid_s
    • I had something like that) - eri

    In general, thanks to all who helped (especially @Sergey). In this link I described what and how to do - https://github.com/Rashid-S/ADAM-3600

    1. Introduction

    This project consistently outlines the steps for building and cross-compiling the Python 3.5.5 interpreter for the ARM core. Cross-compilation was performed on Ubuntu 12.04 OS, simulated on a virtual machine. The interpreter is designed to work in Linux on the Adam-3600 industrial controller (hereinafter referred to as PLC), but it can also be used on other controllers (I don’t know, didn’t check).

    2. Dependencies

    Install updates

     $ sudo apt-get install update $ sudo apt-get install upgrade 

    Install the following libraries

     $ sudo apt-get install libssl-dev $ sudo apt-get install libffi-dev $ sudo apt-get install gcc-arm-linux-gnueabihf $ sudo apt-get install dff $ reboot 

    Check the version of arm-linux-gnueabihf-gcc with the command arm-linux-gnueabihf-gcc --version . The version should be 4.6.3.

    3. Cross-compiling OpenSSL 1.0.1t

     $ cd $HOME wget https://www.openssl.org/source/old/1.0.1/openssl-1.0.1t.tar.gz tar xvzf openssl-1.0.1t.tar.gz $ cd openssl-1.0.1t $ ./Configure linux-generic32 shared --cross-compile-prefix=arm-linux-gnueabihf- $ make $ sudo make install $ mkdir lib $ cp ./*.{so,so.1.0.0,a,pc} ./lib 

    4. Cross-compiling and building Python-3.5.5

    Run sequentially commands

     $ cd $HOME $ mkdir PythonSrc $ cd PythonSrc $ wget https://www.python.org/ftp/python/3.5.5/Python-3.5.5.tgz $ tar zxf Python-3.5.5.tgz $ mv Python-3.5.5 Python-3.5.5-host $ cd Python-3.5.5-host $ ./configure --prefix=$HOME/PythonSrc/PythonHost $ make python Parser/pgen $ make install 
     $ cd $HOME $ wget https://www.python.org/ftp/python/3.5.5/Python-3.5.5.tgz $ tar zxf Python-3.5.5.tgz $ cd Python-3.5.5 $ export CC=arm-linux-gnueabihf-gcc $ export CXX=arm-linux-gnueabihf-g++ $ export AR=arm-linux-gnueabihf-ar $ export RANLIB=arm-linux-gnueabihf-ranlib $ export ac_cv_file__dev_ptmx=no $ export ac_cv_file__dev_ptc=no $ export ac_cv_have_long_long_format=yes $ export PATH=/home/rashid/PythonSrc/PythonHost/bin:$PATH $ export OPENSSL_ROOT=/home/rashid/openssl-1.0.1t $ ./configure --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf --build=x86_64-linux-gnu --prefix=$HOME/PythonSrc/PythonTarget --disable-ipv6 --enable-shared $ export HOSTPYTHON=$HOME/PythonSrc/Python-3.5.5-host/python3 $ export HOSTPGEN=$HOME/Python-3.5.5-host/Parser/pgen $ export BLDSHARED="arm-linux-gnueabihf-gcc -shared" $ export CROSS_COMPILE=arm-linux-gnueabihf- $ export CROSS_COMPILE_TARGET=yes $ export HOSTARCH=arm-linux $ export BUILDARCH=arm-linux-gnueabihf 

    /usr/rashid/Python-3.5.5/Modules/Setup.dist files /usr/rashid/Python-3.5.5/Modules/Setup.dist and /usr/rashid/Python-3.5.5/setup.py . Further

     $ make $ make install 

    The compiled project should appear in the $HOME/PythonSrc/PythonTarget/

    5. Run interpreter on Adam-3600

    There are four directories in the $HOME/PythonSrc/PythonTarget/ directory: /bin, /include, /lib, /share . I copied the contents of each directory into the same directories on the PLC - /usr/bin, /usr/include, /usr/lib, /usr/share respectively, with the exception of the /lib/python3.5/test directory, since the PLC does not there is so much space, and there is no need for this catalog.

    Log in to the /usr/bin . Run on command line

     chmod +x python3.5 

    Further

     python3.5 

    In response, an interpreter prompt should appear on the command line.

     Python 3.5.5 (default, Apr 28 2019, 20:19:45) [GCC 4.6.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>>