Porting to python3

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
triplus
Posts: 8676
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Postby triplus » Sat Mar 16, 2019 1:50 am

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: 542
Joined: Tue May 19, 2015 1:11 am

Re: Porting to python3

Postby ezzieyguywuf » Sat Mar 16, 2019 2:15 am

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
Posts: 5478
Joined: Thu Jan 05, 2017 9:03 pm

Re: Porting to python3

Postby Kunda1 » Sat Mar 16, 2019 11:46 am

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
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
ezzieyguywuf
Posts: 542
Joined: Tue May 19, 2015 1:11 am

Re: Porting to python3

Postby ezzieyguywuf » Sat Mar 16, 2019 1:26 pm

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
Posts: 8676
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Postby triplus » Sun Mar 17, 2019 1:52 pm

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
Posts: 2649
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Porting to python3

Postby PrzemoF » 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.
User avatar
kkremitzki
Posts: 1708
Joined: Thu Mar 03, 2016 9:52 pm
Location: Texas

Re: Porting to python3

Postby kkremitzki » Wed Mar 20, 2019 7:36 pm

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
Posts: 2649
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Porting to python3

Postby PrzemoF » Wed Mar 20, 2019 7:45 pm

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
Posts: 8676
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Postby triplus » Wed Mar 20, 2019 10:22 pm

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
Posts: 2649
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Porting to python3

Postby PrzemoF » Thu Mar 21, 2019 7:38 pm

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