Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install and find SyntaxError: invalid syntax #69

Closed
cbjcbj opened this issue Aug 19, 2016 · 18 comments
Closed

Install and find SyntaxError: invalid syntax #69

cbjcbj opened this issue Aug 19, 2016 · 18 comments

Comments

@cbjcbj
Copy link

cbjcbj commented Aug 19, 2016

Hi, I follow the install instruction:

export PYTHON_LIBRARY=/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
export PYTHON_INCLUDE_DIR=/usr/include/python2.7
python setup.py install

and get SyntaxError: invalid syntax

generating python binding
[ 20%] Swig source
Scanning dependencies of target _tinysplinepython
[ 40%] Building CXX object CMakeFiles/_tinysplinepython.dir/python/tinysplinepythonPYTHON_wrap.o
[ 60%] Building C object CMakeFiles/_tinysplinepython.dir/tinyspline.o
[ 80%] Building CXX object CMakeFiles/_tinysplinepython.dir/tinysplinecpp.o
[100%] Linking CXX shared module _tinysplinepython.so
[100%] Built target _tinysplinepython
creating file: __init__.py
package init file './__init__.py' not found (or not a regular file)
package init file './__init__.py' not found (or not a regular file)
removing cmake build directory
running install_lib
copying build/lib.linux-x86_64-2.7/tinyspline/tinyspline.py -> /usr/local/lib/python2.7/dist-packages/tinyspline
copying build/lib.linux-x86_64-2.7/tinyspline/_tinysplinepython.so -> /usr/local/lib/python2.7/dist-packages/tinyspline
copying build/lib.linux-x86_64-2.7/tinyspline/__init__.py -> /usr/local/lib/python2.7/dist-packages/tinyspline
byte-compiling /usr/local/lib/python2.7/dist-packages/tinyspline/tinyspline.py to tinyspline.pyc
  File "/usr/local/lib/python2.7/dist-packages/tinyspline/tinyspline.py", line 111
    def ts_deboornet_default(deBoorNet: 'tsDeBoorNet *') -> "void":
                                      ^
SyntaxError: invalid syntax

Could you please help? Thank you.

@msteinbeck
Copy link
Owner

Did you install python2 headers with?:

sudo apt-get install libpython2.7-dev

@cbjcbj
Copy link
Author

cbjcbj commented Aug 19, 2016

Yes, I already install libpython2.7-dev.

@msteinbeck
Copy link
Owner

msteinbeck commented Aug 19, 2016

Do you have multiple versions of python installed on your system? It looks like the generated python file belongs to python3, though, I'm not entirely sure.

@msteinbeck
Copy link
Owner

Could you please paste the whole output of CMake? There should be a line telling us which mode (python2 or python3) has been used to create the binding.

@cbjcbj
Copy link
Author

cbjcbj commented Aug 19, 2016

Yes, I have both python 3 and python 2. The following is the whole output of

sudo python setup.py install
cbj@cbj-703:~/docs/learning/tinyspline$ sudo python setup.py install
running install
running build
running build_py
creating cmake build directory
creating /home/cbj/docs/learning/tinyspline/build/lib.linux-x86_64-2.7/build
generating cmake tree
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SWIG: /usr/local/bin/swig (found suitable version "3.0.10", minimum required is "3.0.1") 
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (found version "3.4.3") 
-- Using Python 3 mode.
-- Could NOT find JNI (missing:  JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 
-- Could NOT find any suitable C# compiler.
-- Could NOT find Ruby (missing:  RUBY_INCLUDE_DIR RUBY_LIBRARY RUBY_CONFIG_INCLUDE_DIR) (found version "1.9.1")
CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.6)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: /home/cbj/docs/learning/tinyspline/build/lib.linux-x86_64-2.7/build
generating python binding
[ 20%] Swig source
Scanning dependencies of target _tinysplinepython
[ 40%] Building CXX object CMakeFiles/_tinysplinepython.dir/python/tinysplinepythonPYTHON_wrap.o
[ 60%] Building C object CMakeFiles/_tinysplinepython.dir/tinyspline.o
[ 80%] Building CXX object CMakeFiles/_tinysplinepython.dir/tinysplinecpp.o
[100%] Linking CXX shared module _tinysplinepython.so
[100%] Built target _tinysplinepython
creating file: __init__.py
package init file './__init__.py' not found (or not a regular file)
package init file './__init__.py' not found (or not a regular file)
removing cmake build directory
running install_lib
copying build/lib.linux-x86_64-2.7/tinyspline/tinyspline.py -> /usr/local/lib/python2.7/dist-packages/tinyspline
copying build/lib.linux-x86_64-2.7/tinyspline/_tinysplinepython.so -> /usr/local/lib/python2.7/dist-packages/tinyspline
copying build/lib.linux-x86_64-2.7/tinyspline/__init__.py -> /usr/local/lib/python2.7/dist-packages/tinyspline
byte-compiling /usr/local/lib/python2.7/dist-packages/tinyspline/tinyspline.py to tinyspline.pyc
  File "/usr/local/lib/python2.7/dist-packages/tinyspline/tinyspline.py", line 111
    def ts_deboornet_default(deBoorNet: 'tsDeBoorNet *') -> "void":
                                      ^
SyntaxError: invalid syntax

byte-compiling /usr/local/lib/python2.7/dist-packages/tinyspline/__init__.py to __init__.pyc
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/tinyspline-0.1.2.egg-info
Writing /usr/local/lib/python2.7/dist-packages/tinyspline-0.1.2.egg-info

@cbjcbj
Copy link
Author

cbjcbj commented Aug 19, 2016

Should I run cmake before I run python setup.py? When I run cmake .., I get these output:

cbj@cbj-703:~/docs/learning/tinyspline/build$ cmake ..
-- Using environment variables PYTHON_LIBRARY and PYTHON_INCLUDE_DIR
-- Found PythonLibs: /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so (found version "2.7.6") 
-- Using Python 2 mode.
-- Could NOT find JNI (missing:  JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 
-- Could NOT find any suitable C# compiler.
-- Could NOT find Ruby (missing:  RUBY_INCLUDE_DIR RUBY_LIBRARY RUBY_CONFIG_INCLUDE_DIR) (found version "1.9.1")
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GLUT_Xi_LIBRARY (ADVANCED)
    linked by target "bspline" in directory /home/cbj/docs/learning/tinyspline/examples/c
    linked by target "beziers" in directory /home/cbj/docs/learning/tinyspline/examples/c
    linked by target "split" in directory /home/cbj/docs/learning/tinyspline/examples/c
    linked by target "derivative" in directory /home/cbj/docs/learning/tinyspline/examples/c
    linked by target "triangle-nurbs" in directory /home/cbj/docs/learning/tinyspline/examples/c
    linked by target "interpolation" in directory /home/cbj/docs/learning/tinyspline/examples/c
    linked by target "buckle" in directory /home/cbj/docs/learning/tinyspline/examples/c
    linked by target "triangle" in directory /home/cbj/docs/learning/tinyspline/examples/c
    linked by target "nurbs" in directory /home/cbj/docs/learning/tinyspline/examples/c

-- Configuring incomplete, errors occurred!
See also "/home/cbj/docs/learning/tinyspline/CMakeFiles/CMakeOutput.log".

@msteinbeck
Copy link
Owner

As we can see in your log, CMake generated a python 3 interface file:

...
-- Found -- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (found version "3.4.3") 
-- Using Python 3 mode.PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (found version "3.4.3") 
-- Using Python 3 mode.
...

It looks like python setup.py install does not pass the exported environment variables to CMake.

@cbjcbj
Copy link
Author

cbjcbj commented Aug 19, 2016

So what can I do to make it work? Thank you!

@msteinbeck
Copy link
Owner

msteinbeck commented Aug 19, 2016

So what can I do to make it work? Thank you!

For now I was not able to properly pass the shell environment variables to python/cmake. However, you can you edit your setup.py file and add putenv to set PYTHON_LIBRARY and PYTHON_INCLUDE_DIR:

...
from shutil import rmtree, copy2
from os import path, chdir, putenv # add putenv
from glob import glob
import subprocess

cmake_bin = "cmake"
cmake_build_config = "Release"
cmake_build_target = "_tinysplinepython"

# export your environment variables
putenv("PYTHON_LIBRARY", "/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so")
putenv("PYTHON_INCLUDE_DIR", "/usr/include/python2.7")
...

I will try to properly fix this issue as soon as possible (later this day).

@msteinbeck
Copy link
Owner

msteinbeck commented Aug 19, 2016

I found that the environment variables exported as a regular user are not available with sudo. Therefore, another fix is to become root before exporting the variables and installing the binding.

sudo -s
export PYTHON_LIBRARY=/usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
export PYTHON_INCLUDE_DIR=/usr/include/python2.7
python setup.py install

@msteinbeck
Copy link
Owner

Have a look at: http://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo. It shows that with sudo -E a user may keep his/her existing environment variables. Thus, you should be able to export the variables as regular user and run:

sudo -E python setup.py install

I tried it on my machine and it works flawless.

@cbjcbj
Copy link
Author

cbjcbj commented Aug 19, 2016

Thank you! I will take a try! Maybe on Monday, we are off now. Wish you a good weekend^_^

@cbjcbj
Copy link
Author

cbjcbj commented Aug 22, 2016

Hi, I use git pull to update and try sudo -E, it finds python 2.7 but it still does not work. When I run quickstart.py, I get:

cbj@cbj-703:~/docs/learning/tinyspline/examples/python$ python2 quickstart.py 
Traceback (most recent call last):
  File "quickstart.py", line 22, in <module>
    spline.ctrlp = ctrlp
  File "/usr/local/lib/python2.7/dist-packages/tinyspline/tinyspline.py", line 356, in <lambda>
    BSpline.ctrlp = property(lambda self: list(self.__ctrlp()), lambda self, value: self.__setCtrlp(value))
TypeError: in method 'BSpline___setCtrlp', argument 2 of type 'std::vector< ts::rational,std::allocator< ts::rational > > const'

When I use python3 to run I get the same output

cbj@cbj-703:~/docs/learning/tinyspline/examples/python$ python3 quickstart.py 
Traceback (most recent call last):
  File "quickstart.py", line 22, in <module>
    spline.ctrlp = ctrlp
  File "/usr/local/lib/python3.4/dist-packages/tinyspline/tinyspline.py", line 356, in <lambda>
    BSpline.ctrlp = property(lambda self: list(self.__ctrlp()), lambda self, value: self.__setCtrlp(value))
TypeError: in method 'BSpline___setCtrlp', argument 2 of type 'std::vector< ts::rational,std::allocator< ts::rational > > const'

Here is the output of compilation:

cbj@cbj-703:~/docs/learning/tinyspline$ sudo -E python setup.py install
running install
running build
running build_py
creating cmake build directory
creating /home/cbj/docs/learning/tinyspline/build/lib.linux-x86_64-2.7/build
generating cmake tree
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using environment variables 'PYTHON_LIBRARY' and 'PYTHON_INCLUDE_DIR'
-- Found SWIG: /usr/local/bin/swig (found suitable version "3.0.10", minimum required is "3.0.1") 
-- Found PythonLibs: /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so (found version "2.7.6") 
-- Could NOT find JNI (missing:  JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 
-- Could NOT find Ruby (missing:  RUBY_INCLUDE_DIR RUBY_LIBRARY RUBY_CONFIG_INCLUDE_DIR) (found version "1.9.1")
CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.6)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: /home/cbj/docs/learning/tinyspline/build/lib.linux-x86_64-2.7/build
generating python binding
[ 20%] Swig source
Scanning dependencies of target _tinysplinepython
[ 40%] Building CXX object CMakeFiles/_tinysplinepython.dir/python/tinysplinepythonPYTHON_wrap.o
[ 60%] Building C object CMakeFiles/_tinysplinepython.dir/tinyspline.o
[ 80%] Building CXX object CMakeFiles/_tinysplinepython.dir/tinysplinecpp.o
[100%] Linking CXX shared module lib/_tinysplinepython.so
[100%] Built target _tinysplinepython
creating file: __init__.py
package init file './__init__.py' not found (or not a regular file)
package init file './__init__.py' not found (or not a regular file)
removing cmake build directory
running install_lib
copying build/lib.linux-x86_64-2.7/tinyspline/tinyspline.py -> /usr/local/lib/python2.7/dist-packages/tinyspline
copying build/lib.linux-x86_64-2.7/tinyspline/_tinysplinepython.so -> /usr/local/lib/python2.7/dist-packages/tinyspline
copying build/lib.linux-x86_64-2.7/tinyspline/__init__.py -> /usr/local/lib/python2.7/dist-packages/tinyspline
byte-compiling /usr/local/lib/python2.7/dist-packages/tinyspline/tinyspline.py to tinyspline.pyc
byte-compiling /usr/local/lib/python2.7/dist-packages/tinyspline/__init__.py to __init__.pyc
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/tinyspline-0.1.2.egg-info
Writing /usr/local/lib/python2.7/dist-packages/tinyspline-0.1.2.egg-info

@msteinbeck
Copy link
Owner

Looks like an error introduced by the recently added double precision support. Will fix it as soon as possible.

@cbjcbj
Copy link
Author

cbjcbj commented Aug 22, 2016

OK, thank you:)

@msteinbeck
Copy link
Owner

Should be fixed with newest commit.

@msteinbeck
Copy link
Owner

Can I close this one?

@cbjcbj
Copy link
Author

cbjcbj commented Aug 24, 2016

Yes of course:)

@cbjcbj cbjcbj closed this as completed Aug 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants