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!
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Porting to python3

Post by yorik »

This looks like a graphics driver issue (all the screen seems "shifted" up or redrawn "below" the window title bar)...
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Porting to python3

Post by bernd »

It's never to late ... Just wanted to tell you guys that I eventually joined the Py3 Party on ALLk my systems, the work machine and the developing and testing machine :D It is much easier not to wait for Travis to see if a patch is fine because I had no Py3 dev machine ...

It is my own chistmas present. But took me nearly one day.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

Good to hear that. Just don't forget and to start introducing Python 2 issues now! ;)
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Porting to python3

Post by triplus »

ebrahim raeyat wrote: Tue Dec 11, 2018 9:02 pm yes. in interactive python consol in FreeCAD type this:

Code: Select all

import pandas as pd
df = pd.DataFrame()
df.to_excel('/home/ebi/df1.xlsx')
The issue is related to openpyxl import. More specifically, you will need to start PipTools and in addition install lxml package.

Happy Coding!
peterl94
Veteran
Posts: 1001
Joined: Thu May 23, 2013 7:31 pm
Location: United States

Re: Porting to python3

Post by peterl94 »

Are you guys aware of this? Got this error first time testing a macOS py3 build:

Code: Select all

memoryview: a bytes-like object is required, not 'str'
Traceback (most recent call last):
  File "<string>", line 66, in Initialize
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/Mod/OpenSCAD/OpenSCADUtils.py", line 78, in searchforopenscadexe
    stdout,stderr = p1.communicate(ascript)
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/lib/python3.6/subprocess.py", line 843, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/lib/python3.6/subprocess.py", line 1499, in _communicate
    input_view = memoryview(self._input)
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Porting to python3

Post by wmayer »

peterl94 wrote: Wed Jan 02, 2019 6:12 am Are you guys aware of this? Got this error first time testing a macOS py3 build:

Code: Select all

memoryview: a bytes-like object is required, not 'str'
Traceback (most recent call last):
  File "<string>", line 66, in Initialize
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/Mod/OpenSCAD/OpenSCADUtils.py", line 78, in searchforopenscadexe
    stdout,stderr = p1.communicate(ascript)
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/lib/python3.6/subprocess.py", line 843, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/lib/python3.6/subprocess.py", line 1499, in _communicate
    input_view = memoryview(self._input)
No problem on Windows or Linux. Obviously the function communicate expects bytes instead of str objects. Can you test if replacing

Code: Select all

        ascript = ('tell application "Finder"\n'
        'POSIX path of (application file id "org.openscad.OpenSCAD"'
        'as alias)\n'
        'end tell')
with

Code: Select all

        ascript = (b'tell application "Finder"\n'
        'POSIX path of (application file id "org.openscad.OpenSCAD"'
        'as alias)\n'
        'end tell')
fixes the problem (note the b at the beginning)?
peterl94
Veteran
Posts: 1001
Joined: Thu May 23, 2013 7:31 pm
Location: United States

Re: Porting to python3

Post by peterl94 »

wmayer wrote: Wed Jan 02, 2019 1:55 pm fixes the problem (note the b at the beginning)
Thanks, that did fix it.

There is one more:

Code: Select all

Traceback (most recent call last):
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/Mod/Test/TestPythonSyntax.py", line 44, in testAll
    test_python_syntax(mod_dir, self.whitelist)
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/Mod/Test/TestPythonSyntax.py", line 19, in test_python_syntax
    ast.parse(py_file.read())
  File "/Users/peter/FreeCAD/install/FreeCAD.app/Contents/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 204: ordinal not in range(128)
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Porting to python3

Post by wmayer »

I don't know what exactly the problem is. py_file is opened with encoding=utf-8 but maybe ast.parse fails. Any idea for which input file it fails?
peterl94
Veteran
Posts: 1001
Joined: Thu May 23, 2013 7:31 pm
Location: United States

Re: Porting to python3

Post by peterl94 »

Found the problem. Not sure why it is not a problem for other platforms.

Code: Select all

diff --git a/src/Mod/Test/TestPythonSyntax.py b/src/Mod/Test/TestPythonSyntax.py
index f529c5e78..f30536689 100644
--- a/src/Mod/Test/TestPythonSyntax.py
+++ b/src/Mod/Test/TestPythonSyntax.py
@@ -11,7 +11,7 @@ def test_python_syntax(rootdir, whitelist=None):
     for sub_dir, dirs, files in os.walk(rootdir):
         for fn in files:
             kargs = {}
-            if sys.version_info.major > 3:
+            if sys.version_info.major >= 3:
                 kargs["encoding"] = "utf-8"
             if (not fn in whitelist) and os.path.splitext(fn)[1] == '.py':
                 with open(os.path.join(sub_dir, fn), **kargs) as py_file:
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Porting to python3

Post by wmayer »

Found the problem. Not sure why it is not a problem for other platforms.
Good catch! Just overlooked the ">". But no idea why there is no problem on other platforms.
Post Reply