1

I have compiled python3.6.5 from the source and linked it to my compiled openssl as the following:

export LDFLAGS="-L/usr/local/openssl/lib/ -L/usr/local/openssl/lib64/"
export LD_LIBRARY_PATH="/usr/local/openssl/lib/:/usr/local/openssl/lib64/"
export CPPFLAGS="-I/usr/local/openssl/include -I/usr/local/openssl/include/openssl"
./configure --prefix=/usr/local/openssl/
make
make install

And the openssl is installed as follows:

./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib
make
make install

/my/path/ in the above instructions is replaced with /usr/local/openssl/ where openssl is also built in Ubuntu 18 but I compiled it from the source because the system one is missing some features I need.

Now, I want to run my python program using my compile python not the system one. How to do this? If I write python myprog.py, it will run the system's python.

  • Isn't your compiled python under /my/path? – slm Aug 5 '18 at 5:18
  • No. the compiled python is under the home. The two libraries are installed under the home directory as follows: home/Python-3.6.5 and home/openssl-1.1.0g. The /my/path/ that you see in my post has been replaced by /usr/local/openssl/. The OpenSSL library is configured like this: ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib then make and make install – user9371654 Aug 5 '18 at 5:30
  • Rather than do it like this, why not use virtualenv or venv? docs.python.org/3/library/venv.html. Makes for a far simpler way to manage your own Pythons w/o having to re-invent wheels. – slm Aug 5 '18 at 5:32
  • @slm I prefer normal settings. – user9371654 Aug 5 '18 at 6:09
0

If your have a custom Python installed under /some/path:

  1. Adding the shebang line in myscript.py will select the custom python when running it as executable script:

    #!/some/path/bin/python
    import sys
    print(sys.version)
    

    Running the script:

    $ chmod +x myscript.py
    $ ./myscript.py
    2.7.10 (default, Oct  6 2017, 22:29:07)
    [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
    
  2. You can explicitly pass the path to python executable to run the script:

    $ /some/path/bin/python myscript.py
    
  3. Prepending /some/path/bin to PATH will select the custom python instead of the system one:

    $ PATH=/some/path/bin:$PATH python myscript.py
    

Judging by the line ./configure --prefix=/usr/local/openssl/ you've provided, it looks like you installed custom Python under /usr/local/openssl; the bin dir should thus be /usr/local/openssl/bin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.