Porting to python3

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
yorik
Site Admin
Posts: 11458
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: Porting to python3

Postby yorik » Sun Dec 23, 2018 1:13 pm

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

Re: Porting to python3

Postby bernd » Sun Dec 23, 2018 3:53 pm

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

Re: Porting to python3

Postby triplus » Sun Dec 23, 2018 4:02 pm

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

Re: Porting to python3

Postby triplus » Sun Dec 23, 2018 4:05 pm

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
Posts: 999
Joined: Thu May 23, 2013 7:31 pm
Location: United States

Re: Porting to python3

Postby peterl94 » 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)
wmayer
Site Admin
Posts: 14635
Joined: Thu Feb 19, 2009 10:32 am

Re: Porting to python3

Postby wmayer » Wed Jan 02, 2019 1:55 pm

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
Posts: 999
Joined: Thu May 23, 2013 7:31 pm
Location: United States

Re: Porting to python3

Postby peterl94 » Wed Jan 02, 2019 2:45 pm

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
Site Admin
Posts: 14635
Joined: Thu Feb 19, 2009 10:32 am

Re: Porting to python3

Postby wmayer » Wed Jan 02, 2019 3:31 pm

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
Posts: 999
Joined: Thu May 23, 2013 7:31 pm
Location: United States

Re: Porting to python3

Postby peterl94 » Thu Jan 03, 2019 6:39 am

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
Site Admin
Posts: 14635
Joined: Thu Feb 19, 2009 10:32 am

Re: Porting to python3

Postby wmayer » Thu Jan 03, 2019 9:42 am

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.