LudovicRousseau / pyscard

pyscard smartcard library for python
http://pyscard.sourceforge.net/
GNU Lesser General Public License v2.1
386 stars 111 forks source link

1.9.0 release not working for python 2.7 #12

Closed sjenning closed 8 years ago

sjenning commented 9 years ago
$ python
Python 2.7.10 (default, Jul  5 2015, 14:15:43) 
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import smartcard
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/smartcard/__init__.py", line 32, in <module>
    from smartcard.System import listReaders
  File "/usr/lib64/python2.7/site-packages/smartcard/System.py", line 28, in <module>
    import smartcard.reader.ReaderFactory
  File "/usr/lib64/python2.7/site-packages/smartcard/reader/ReaderFactory.py", line 34, in <module>
    from smartcard.pcsc.PCSCReader import PCSCReader
  File "/usr/lib64/python2.7/site-packages/smartcard/pcsc/PCSCReader.py", line 28, in <module>
    from smartcard.pcsc.PCSCContext import PCSCContext
  File "/usr/lib64/python2.7/site-packages/smartcard/pcsc/PCSCContext.py", line 27, in <module>
    from smartcard.scard import *
  File "/usr/lib64/python2.7/site-packages/smartcard/scard/__init__.py", line 1, in <module>
    from smartcard.scard.scard import *
  File "/usr/lib64/python2.7/site-packages/smartcard/scard/scard.py", line 830, in <module>
    SCARD_SCOPE_USER = _scard.SCARD_SCOPE_USER
AttributeError: 'module' object has no attribute 'SCARD_SCOPE_USER'

Seems like something up with swig, but I'm not a python guy. Any help appreciated!

LudovicRousseau commented 9 years ago

How did you install pyscard? from source code?

sjenning commented 9 years ago

Gah. I was building from source (rpmbuild), but some compiler flags in the build env were messing it up. Nevermind!

cluck commented 9 years ago

I just bumped into this error on OSX 10.10 using pip install --user pyscard.

This is related to swig/swig#250. In other words, different versions of Swig produce smartcard/scard/_scard.so that need different versions of smartcard/scard/scard.py that is not compatible among versions. Thus, smartcard/scard/scard.py should be re-generated together with _scard.so during installation, instead of being distributed as source file.

A quick comparison among the various smartcard/scard/scard.py produced here, it looks to me as if the version distributed with pip does not match the definition in smartcard/scard/scard.i anymore anyway.

LudovicRousseau commented 9 years ago

@cluck do you have a patch to propose? I am not a setuptools expert.

ghost commented 9 years ago

The same behavior can be seen on Windows with Python 2.7.10. I tried to manually run latest swig and regenerate the files as suggested with no result.

sebastianarena commented 9 years ago

+1 for me Working on OSX 10.10.5 and python 2.7.10 Doing pip install pyscard will install 1.9.0 and can't run not even the examples with error AttributeError: 'module' object has no attribute 'SCARD_SCOPE_USER' Installing using pip install <url to master.zip> makes a different error saying scard module does not exist

Any help? Does python 3 fix this issue? Any workarounds? I couldn't understand what other user this as workaround with swig and such.

Anything I can help, let me know.

cluck commented 9 years ago

I think the problem happens in the process of creating the source archives that are uploaded to sourceforce and pypi: they differ from the output of python setup.py sdist on a clean checkout and in particular they contain the file smartcard/scard/scard.py.

If this file wasn't present in the source, it would be created in the build_ext step, in a format that is suitable to the generated wrapper.

LudovicRousseau commented 9 years ago

@cluck I think you are right. Can someone propose a patch so that python setup.py sdist does the correct thing?

cluck commented 8 years ago

I think that starting with a clean checkout and running python setup.py sdist as the sole command is the only option for now.

I suspect it to be a bug in the realm of Distutils/Setuptools that python setup.py sdist picks up files excluded in in the MANIFEST.in and not being idempotent before/after running python setup.py build or other commands.