Python 3 in pfsense




  • Banned

    @kalle13 said in Python 3 in pfsense:

    and use these repos:
    http://pkg.freebsd.org/freebsd:11:x86:64/latest/All/

    Just don't come crying when the next pfSense update fails.



  • @grimson Really? I did not know that. Is this for sure when I am installing other repos?


  • Banned

    @kalle13 said in Python 3 in pfsense:

    @grimson Really? I did not know that. Is this for sure when I am installing other repos?

    It has happened in the past already.


  • Rebel Alliance Developer Netgate

    He's right. Do not be surprised when that causes problems. Do not do that on a production system you care about.



  • On the other hand : if one is comfortable with installing from the standard FreeBSD repository, upgrading by re installing "from scratch" will be no issue at all.



  • @grimson Ok, thanks for your advice. I keep that in mind when the next upodate arrives. What can I do if the update fails?



  • @kalle13 Reinstall fresh, restore your xml config and then re-add the Python3 package. Plus, the update may not fail, but it may blow away your Python3 package and cause the things you need it for to break.



  • @kom Thanks for your advice!



  • Hi everyone, sorry for being this thread up again but what about python 2 in the meantime? I saw that there is already python 2 inside pfsense using "pkg info" but I am not able to run python commands. Do I need to do some sort of extraction?


  • Rebel Alliance Developer Netgate

    @couldntmakeupone said in Python 3 in pfsense:

    Hi everyone, sorry for being this thread up again but what about python 2 in the meantime? I saw that there is already python 2 inside pfsense using "pkg info" but I am not able to run python commands. Do I need to do some sort of extraction?

    Python 2.7 is there and works fine, it just isn't in the python command, but python2.7. If you must have it available when typing python then make an alias or symlink.



  • @jimp said in Python 3 in pfsense:

    symlink.

    So, can I just run python 2.7 programs in pfsense by using ./python.py?


  • Rebel Alliance Developer Netgate

    If you edit the shabang line to use the correct path to the binary, yes. If you have more questions, please start your own thread as it isn't related to this topic.



  • To solve this I have created a public repo on GitHub with precompiled Python 3 binaries for specific releases of pfSense:

    pfSense Python 3

    If you follow the instructions, it's a very straightforward process and will allow you to choose whatever Python 3 version works for you :)



  • @jwsi Thanks very much for this. I was wondering how to approach this issue.

    I was wondering if I could simplify the installation procedure... I just want python3.6 for amd64, can I just download from github to /root on my pfSense box?

    curl -L -o Python3.6_pfSense2.4.4-RELEASE-p3_amd64.txz  https://github.com/ultrahorizon/pfSense-Python3/raw/master/2.4.4-RELEASE-p3/amd64/3.6.txz
    pkg add Python3.6_pfSense2.4.4-RELEASE-p3_amd64.txz
    

    I'm assuming that it does not matter that I renamed the file Python3.6_pfSense2.4.4-RELEASE-p3_amd64.txz as long as I use the same file name in the pkg add command.
    (Note the -L option since github redirects the URL obtained by saving the link on the download button.)

    I'm hoping this is OK so I don't need to clone the whole repo and install git.



  • Hi @guardian,

    So this is actually documented in the "Easy Installation" section of the README.

    For Python 3.6 on amd64 you can simply execute:

    cd /tmp
    fetch https://github.com/ultrahorizon/pfSense-Python3/raw/master/2.4.4-RELEASE-p3/amd64/3.6.txz
    pkg add 3.6.txz
    

    Then the file will be removed from the /tmp folder in due course. I would probably advise downloading to the tmp folder or deleting the .txz file after install because there's no need to keep it around.

    Let me know if that works for you ☺



  • @jwsi Thanks... that does the fetch just fine... still working a few things out before I run it.

    I assume this leaves python2.7 Installed and I run the new python as /usr/local/bin/python3.6 correct?

    Does install include pip? If not, how do I install it (I need a couple of extra packages)

    What command do I use to run pip for python3.6 instead of python2.7?

    P.S.: For the benefit of anyone running this that doesn't know their way around the command line, they can just run rm 3.6.txz after the install is done to get rid of the file.



  • Great to hear that it works @guardian.

    If you reload the pfSense shell after installing (type exit then hit option 8 again) you will be able to use Python 3.6 by typing python3.6 in the command line. However, the full path you quoted is indeed correct too.

    With regards to pip, this is already bundled as a module. To install simply execute:

    python3.6 -m ensurepip

    Then Python3's pip is available under the command pip3 (another shell reload will likely be required here...). It's also advised to upgrade pip to the latest version too. Therefore, after installation execute:

    pip3 install --upgrade pip



  • @jwsi said in Python 3 in pfsense:

    Great to hear that it works @guardian.

    If you reload the pfSense shell after installing (type exit then hit option 8 again) you will be able to use Python 3.6 by typing python3.6 in the command line. However, the full path you quoted is indeed correct too.

    With regards to pip, this is already bundled as a module. To install simply execute:

    python3.6 -m ensurepip

    Then Python3's pip is available under the command pip3 (another shell reload will likely be required here...). It's also advised to upgrade pip to the latest version too. Therefore, after installation execute:

    pip3 install --upgrade pip

    @jwsi thank you very much. I've just used default python2.7 on all my systems till now (don't do much dev-just the odd admin/helper script), so now I have to learn how to do things properly so that really helps. I will wait till I upgrade from p2 -> p3 before running, but I'll report back to confirm that everything works OK.



  • @guardian great! Look forward to hearing how you get on ☺


Log in to reply