Porting to python3

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

ezzieyguywuf wrote: Sat Mar 16, 2019 1:40 am however my issue is specifically with shiboken and pyside, and as you can see from your link we don't really have that available in gentoo's package management system.

I'm attempting to utilize this in pip via a virtual environment.
No Shiboken2 and PySide2, no fun. In addition i am not all that sure if Qt for Python official wheel is currently useful at all for FreeCAD compiling purposes.

Therefore if you would like to compile FreeCAD yourself, on Gentoo, currently Conda is likely your best bet.
ezzieyguywuf
Posts: 656
Joined: Tue May 19, 2015 1:11 am

Re: Porting to python3

Post by ezzieyguywuf »

triplus wrote: Sat Mar 16, 2019 1:50 am No Shiboken2 and PySide2, no fun. In addition i am not all that sure if Qt for Python official wheel is currently useful at all for FreeCAD compiling purposes.

Therefore if you would like to compile FreeCAD yourself, on Gentoo, currently Conda is likely your best bet.
I've actually had some limited success installing these via pip in a virtual environment. I had to hack on freecad a bit in order to recognize/respect the virtual environment (see below), but the Part workbench appears to compile and run just fine using this method.

I was beginning to put together a pull request, but that's when I realized that I needed to manually specify the Shiboken2 and PySide2 installations, thus my original question.

Here is the patch to enable python to recognize virtual environments:

Code: Select all

[diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp
index 927a4e101..5a35ec40d 100644
--- a/src/Base/Interpreter.cpp
+++ b/src/Base/Interpreter.cpp
@@ -492,6 +492,15 @@ const char* InterpreterSingleton::init(int argc,char *argv[])
         // https://bugs.python.org/issue17797#msg197474
         //
         Py_Initialize();
+        PyRun_SimpleString(R"(
+# Check for virtualenv, and activate if present. See https://virtualenv.pypa.io/en/latest/userguide/#using-virtualenv-without-bin-python
+import os
+import sys
+base_path = os.getenv("VIRTUAL_ENV")
+if not base_path is None:
+    activate_this = os.path.join(base_path, "bin", "activate_this.py")
+    exec(open(activate_this).read(), {'__file__':activate_this})
+)");
         PyEval_InitThreads();
 #if PY_MAJOR_VERSION >= 3
         size_t size = argc;
/code]
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Porting to python3

Post by Kunda1 »

ezzieyguywuf wrote: Sat Mar 16, 2019 1:40 am however my issue is specifically with shiboken and pyside, and as you can see from your link we don't really have that available in gentoo's package management system.
Gentoo Pyside2/Shiboken2 ticket: https://bugs.gentoo.org/624682
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
ezzieyguywuf
Posts: 656
Joined: Tue May 19, 2015 1:11 am

Re: Porting to python3

Post by ezzieyguywuf »

Kunda1 wrote: Sat Mar 16, 2019 11:46 am Gentoo Pyside2/Shiboken2 ticket: https://bugs.gentoo.org/624682
@Kunda1, thanks for the link. As this is still "In Progress" though, and not available in the official repositories, I figured it'd make sense to attempt to use them via pip and a virtual environment. This is a pretty typical workflow when using python (isn't that what Conda does?) and as such, I think it makes sense that FreeCAD should be able to operate in this way.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

ezzieyguywuf wrote: Sat Mar 16, 2019 2:15 am I've actually had some limited success installing these via pip in a virtual environment. I had to hack on freecad a bit in order to recognize/respect the virtual environment (see below), but the Part workbench appears to compile and run just fine using this method.
Limited success is likely possible, yes. When it comes to C++ modules. For anything else, best if you wait for Gentoo Linux to provide Qt for Python, or try out Conda.
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Porting to python3

Post by PrzemoF »

I'm trying to build FreeCAD for fedora 30, but the distro dropped python-pivy - now it's python3-pivy. What's the status of migrating FreeCAD to python3? Is it worth to push the build to be completely python3? I have FreeCAD build working, but without Draft workbench.
User avatar
kkremitzki
Veteran
Posts: 2515
Joined: Thu Mar 03, 2016 9:52 pm
Location: Illinois

Re: Porting to python3

Post by kkremitzki »

PrzemoF wrote: Wed Mar 20, 2019 7:17 pm I'm trying to build FreeCAD for fedora 30, but the distro dropped python-pivy - now it's python3-pivy. What's the status of migrating FreeCAD to python3? Is it worth to push the build to be completely python3? I have FreeCAD build working, but without Draft workbench.
The blocker is the packaging of PySide 2 for Fedora. I noticed on the fedora-devel mailing list recently that Richard Shaw, the Fedora maintainer of FreeCAD, is almost finished with that. As soon as Python 3 PySide 2 packages are available, the FreeCAD package can fully transition to Python 3.
Like my FreeCAD work? I'd appreciate any level of support via Patreon, Liberapay, or PayPal! Read more about what I do at my blog.
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Porting to python3

Post by PrzemoF »

I have fedora30 in virtualbox and that's what I see:

Code: Select all

[p@localhost bin]$ dnf search pyside | grep python3
Last metadata expiration check: 0:01:18 ago on Tue 19 Mar 2019 01:11:37 GMT.
python3-pyside.x86_64 : Python bindings for Qt4
python3-pyside.i686 : Python bindings for Qt4
python3-pyside.x86_64 : Python bindings for Qt4[..]
I see the same set on fedora29. Sorry for asking silly questions, but COPR recently included fedora30 and I feel bad about not providing fully functional builds yet :D
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

In my opinion FreeCAD 0.18 is still a bit more mature, when Py2/Qt4 combination is being used. But this is expected to change rather soon, during the next development cycle. Most devs migrated to Py3 toolchain and therefore introduction of Py2 issues is the expected outcome. As you say Py2 Pivy package was dropped from Fedora repositories. And as Qt for Python was not packed for Fedora just yet. FreeCAD Py3/Qt4 builds are indeed the only option you have ATM. Would python3-pivy package need some patching? Or why it can't be used? Maybe for now you could provide the patched version through COPR.
User avatar
PrzemoF
Veteran
Posts: 3520
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Porting to python3

Post by PrzemoF »

I believe python3-pivy is OK, I was concerned about FreeCAD running on python3. I need to do some experiments and see if FreeCAD passes all tests after compilation on fedora30
Post Reply