PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label distutils. Show all posts
Showing posts with label distutils. Show all posts

Thursday, August 25, 2022

[FIXED] What do I need to do to my python code to get it to be a module?

 August 25, 2022     distutils, module, python, setuptools     No comments   

Issue

Can someone tell me what I'm doing wrong to package this as a module: https://github.com/xamox/python-zxing.

My setup.py is as follows:

#!/usr/bin/env python

from distutils.core import setup

setup(
    name='zxing',
    version='0.1',
    description="wrapper for zebra crossing (zxing) barcode library",
    url='http://simplecv.org',
    author='Ingenuitas',
    author_email='public.relations@ingenuitas.com',
    packages=['zxing'],
)

I am trying to do "import zxing". I do setup.py install, puts it in /usr/local/lib/python2.7/dist-packages/, but import zxing doesn't work.

I get the following error:

In [1]: import zxing.zxing
---------------------------------------------------------------------------
ResolutionError                           Traceback (most recent call last)
/home/xamox/<ipython-input-1-9ff7d0755c55> in <module>()
----> 1 import zxing.zxing

/usr/local/bin/zxing.py in <module>()
      3 __requires__ = 'zxing==0.1'
      4 import pkg_resources
----> 5 pkg_resources.run_script('zxing==0.1', 'zxing.py')

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in run_script(self, requires, script_name)
    465         ns.clear()
    466         ns['__name__'] = name
--> 467         self.require(requires)[0].run_script(script_name, ns)
    468 
    469 

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in run_script(self, script_name, namespace)
   1192         script = 'scripts/'+script_name
   1193         if not self.has_metadata(script):
-> 1194             raise ResolutionError("No script named %r" % script_name)
   1195         script_text = self.get_metadata(script).replace('\r\n','\n')
   1196         script_text = script_text.replace('\r','\n')

ResolutionError: No script named 'zxing.py'

Solution

Have a look in the stack trace whose URL you showed in a comment:

/usr/local/bin/zxing.py in <module>()
      3 __requires__ = 'zxing==0.1'
      4 import pkg_resources
----> 5 pkg_resources.run_script('zxing==0.1', 'zxing.py')

That indicates that it is trying to load some guff from /usr/local/bin/zxing.py which contains code that's not in your current version e.g. "import pkg_resources". Looks like debris from a previous experiment. Get rid of it.

Now that you have a clean deck:

It seems rather pointless having an empty __init__.py and a one-source-file package. I suggest that you delete the __init__.py and remove all traces of other experiments (especially "build" directories). If there is a folder /usr/local/lib/python2.7/dist-packages/zxing, remove it.



Answered By - John Machin
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, June 26, 2022

[FIXED] How to tell distutils to use gcc?

 June 26, 2022     compiler-errors, cython, distutils, python     No comments   

Issue

I want to wrap a test project containing C++ and OpenMP code with Cython, and build it with distutils via a setup.py file. The content of my file looks like this:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext


modules = [Extension("Interface",
                     ["Interface.pyx", "Parallel.cpp"],
                     language = "c++",
                     extra_compile_args=["-fopenmp"],
                     extra_link_args=["-fopenmp"])]

for e in modules:
    e.cython_directives = {"embedsignature" : True}

setup(name="Interface",
     cmdclass={"build_ext": build_ext},
     ext_modules=modules)

The -fopenmp flag is used with gcc to compile and link against OpenMP. However, if I just invoke

cls ~/workspace/CythonOpenMP/src $ python3 setup.py build

this flag is not recognized, because the compiler is clang:

running build
running build_ext
skipping 'Interface.cpp' Cython extension (up-to-date)
building 'Interface' extension
cc -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c Interface.cpp -o build/temp.macosx-10.8-x86_64-3.3/Interface.o -fopenmp
clang: warning: argument unused during compilation: '-fopenmp'
cc -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c Parallel.cpp -o build/temp.macosx-10.8-x86_64-3.3/Parallel.o -fopenmp
clang: warning: argument unused during compilation: '-fopenmp'
Parallel.cpp:24:10: warning: unknown pragma ignored [-Wunknown-pragmas]
        #pragma omp parallel for
                ^
1 warning generated.
c++ -bundle -undefined dynamic_lookup -L/usr/local/lib -L/usr/local/opt/sqlite/lib build/temp.macosx-10.8-x86_64-3.3/Interface.o build/temp.macosx-10.8-x86_64-3.3/Parallel.o -o build/lib.macosx-10.8-x86_64-3.3/Interface.so -fopenmp
ld: library not found for -lgomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'c++' failed with exit status 1

I've unsucessfully tried to specify gcc:

cls ~/workspace/CythonOpenMP/src $ python3 setup.py build --compiler=g++-4.7
running build
running build_ext
error: don't know how to compile C/C++ code on platform 'posix' with 'g++-4.7' compiler

How can I tell distutils to use gcc?


Solution

Try setting the "CC" environment variable from inside the setup.py with os.environ.



Answered By - timotimo
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing