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

Python 3 support #11

Closed
ywecur opened this issue May 2, 2016 · 22 comments
Closed

Python 3 support #11

ywecur opened this issue May 2, 2016 · 22 comments
Assignees

Comments

@ywecur
Copy link

ywecur commented May 2, 2016

$ trezor-agent ywecur@wunderkinder.io

Traceback (most recent call last):
  File "/usr/local/bin/trezor-agent", line 9, in <module>
    load_entry_point('trezor-agent==0.6.5', 'console_scripts', 'trezor-agent')()
  File "/usr/local/lib/python3.5/site-packages/trezor_agent/__main__.py", line 131, in run_agent
    with client_factory(curve=args.ecdsa_curve_name) as conn:
  File "/usr/local/lib/python3.5/site-packages/trezor_agent/client.py", line 22, in __init__
    client_wrapper = loader()
  File "/usr/local/lib/python3.5/site-packages/trezor_agent/factory.py", line 86, in load
    device_list.extend(loader())
  File "/usr/local/lib/python3.5/site-packages/trezor_agent/factory.py", line 48, in _load_trezor
    from trezorlib.client import TrezorClient, CallException
  File "/usr/local/lib/python3.5/site-packages/trezorlib/client.py", line 7, in <module>
    import mapping
ImportError: No module named 'mapping'

I then tried $ pip install mapping which returned:

Collecting mapping Could not find a version that satisfies the requirement mapping (from versions: ) No matching distribution found for mapping

Mac OS X El Capitan 10.11.4
Trezor on the latest firmware

@romanz romanz self-assigned this May 3, 2016
@romanz romanz added the MacOS label May 3, 2016
@romanz
Copy link
Owner

romanz commented May 3, 2016

Thanks for reporting this issue!
Could you please try to run it with Python 2?
I think that there may be a problem with Python 3.

@romanz romanz removed the MacOS label May 3, 2016
@romanz
Copy link
Owner

romanz commented May 3, 2016

As far as I understand, this happens due to non-relative import statement at trezorlib/client.py.
In Python 3, it should be written as:

from . import mapping

@romanz romanz added the Python3 label May 3, 2016
@ywecur
Copy link
Author

ywecur commented May 4, 2016

@romanz How do I do that?

@romanz
Copy link
Owner

romanz commented May 4, 2016

Sorry for the inconvenience, I will try to prepare a PR to python-trezor to add support for Python 3.
Meanwhile, you can install Python 2 on your machine, and use it to run trezor-agent...

romanz referenced this issue in trezor/python-trezor May 4, 2016
@romanz
Copy link
Owner

romanz commented May 5, 2016

trezor/python-trezor#56

@slush0
Copy link
Contributor

slush0 commented May 5, 2016

@romanz Please give it a try and tell me back, branch "python3" might work for you already (basic functionality tested on Python 3.4 against emulator, I don't have device with myself).

@romanz
Copy link
Owner

romanz commented May 5, 2016

Thanks a lot for the fixes!
There was a small issue at transport_hid (fixed by trezor/python-trezor#57) and after installing protobuf==3.0.0b2.post2 dependency (since protobuf==2.6.1 isn't compatible with Python 3), trezor-agent works like a charm :)

@romanz
Copy link
Owner

romanz commented May 5, 2016

@ywecur trezor-agent should work now on Python 3.
Please try it and tell me if it works for you.

python3 -m venv /tmp/v3
. /tmp/v3/bin/activate
pip install protobuf==3.0.0b2.post2      # needed for Python 3 support for protobuf
pip install Cython                       # needed to build python-trezor
pip install git+https://github.com/trezor/python-trezor.git@python3
pip install git+https://github.com/romanz/trezor-agent.git@python3

trezor-agent -vv localhost               # should print you NIST256 SSH public key

EDIT: this may not work - see below: #11 (comment)

@romanz romanz changed the title ImportError: No module named 'mapping' Python 3 support May 6, 2016
@romanz
Copy link
Owner

romanz commented May 7, 2016

@ywecur ?

@romanz romanz closed this as completed May 17, 2016
@romanz romanz reopened this May 18, 2016
@romanz
Copy link
Owner

romanz commented May 18, 2016

Somehow, the latest hidapi package fails to build on Python3:

$ pip install hidapi==0.7.99.post16
Downloading/unpacking hidapi==0.7.99.post16
  Using download cache from /home/roman/.pip_download_cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2F35%2Fe0%2Fc6b3da6999043d96cda6a1c44d5f1054058cc6e5c05b1139886444b31bb0%2Fhidapi-0.7.99.post16.tar.gz
  Running setup.py (path:/tmp/pip-build-fbriuxzv/hidapi/setup.py) egg_info for package hidapi

Installing collected packages: hidapi
  Found existing installation: hidapi 0.7.99.post15
    Uninstalling hidapi:
      Successfully uninstalled hidapi
  Running setup.py install for hidapi
    building 'hid' extension
    error: unknown file type '.pyx' (from 'hid.pyx')
    Complete output from command /media/oldhome/roman/Code/trezor/trezor-agent/v3/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-fbriuxzv/hidapi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-7ybd1pqu-record/install-record.txt --single-version-externally-managed --compile --install-headers /media/oldhome/roman/Code/trezor/trezor-agent/v3/include/site/python3.4:
    running install

running build

running build_ext

building 'hid' extension

error: unknown file type '.pyx' (from 'hid.pyx')

However, hidapi==0.7.99.post15 seems to be working fine (on Python 3).

@romanz
Copy link
Owner

romanz commented May 18, 2016

@prusnak Could you please take a look on this issue?

@slush0
Copy link
Contributor

slush0 commented May 18, 2016

What version of Cython do you use? I had similar issue and fixed it by installing older Cython version. I did not dig into the problem more as I needed to focus to another thing, but if this will fix problem for you, we should stick the version and report it to cython.

Edit: nevermind, I see its installation from pip where cython is not required anymore.

@prusnak
Copy link
Contributor

prusnak commented May 18, 2016

setuptools is usually the culprit. make sure you have at least version 19.

edit: setuptools>=19.0 added to install_requires

@romanz
Copy link
Owner

romanz commented May 19, 2016

Thanks! I will retry the installation :)

@romanz
Copy link
Owner

romanz commented May 19, 2016

It works!
The correct installation for Python 3 is:

python3 -m venv /tmp/v3
. /tmp/v3/bin/activate
pip install 'setuptools>=19.0.0'
pip install protobuf==3.0.0b2.post2      # needed for Python 3 support for protobuf
pip install Cython                       # needed to build python-trezor
pip install git+https://github.com/trezor/python-trezor.git
pip install git+https://github.com/romanz/trezor-agent.git

Thanks :)

@romanz
Copy link
Owner

romanz commented Sep 28, 2016

Now the installation should be even simpler:

python3 -m venv /tmp/v3
. /tmp/v3/bin/activate
pip install -U setuptools Cython
pip install git+https://github.com/romanz/trezor-agent.git

@romanz romanz added the SSH label Oct 18, 2016
@ecdsa
Copy link

ecdsa commented Feb 16, 2017

hello, I'm having the same issue as @romanz when trying to install hidapi with python3:
error: unknown file type '.pyx' (from 'hid.pyx')
it works with hidapi==0.7.99.post15, and it fails with any ulterior version.

@prusnak
Copy link
Contributor

prusnak commented Feb 16, 2017 via email

@ecdsa
Copy link

ecdsa commented Feb 16, 2017

  Downloading hidapi-0.7.99.post20.tar.gz (51kB): 51kB downloaded
  Running setup.py (path:/tmp/pip_build_root/hidapi/setup.py) egg_info for package hidapi
    
Downloading/unpacking setuptools>=19.0 (from hidapi)
  Downloading setuptools-34.2.0-py2.py3-none-any.whl (389kB): 389kB downloaded
Requirement already satisfied (use --upgrade to upgrade): six>=1.6.0 in /usr/local/lib/python3.4/dist-packages (from setuptools>=19.0->hidapi)
Requirement already satisfied (use --upgrade to upgrade): appdirs>=1.4.0 in /usr/local/lib/python3.4/dist-packages (from setuptools>=19.0->hidapi)
Requirement already satisfied (use --upgrade to upgrade): packaging>=16.8 in /usr/local/lib/python3.4/dist-packages (from setuptools>=19.0->hidapi)
Installing collected packages: hidapi, setuptools
  Running setup.py install for hidapi
    building 'hid' extension
    error: unknown file type '.pyx' (from 'hid.pyx')
    Complete output from command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/hidapi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-8f18cgdt-record/install-record.txt --single-version-externally-managed --compile:
    running install

running build

running build_ext

building 'hid' extension

error: unknown file type '.pyx' (from 'hid.pyx')

@ecdsa
Copy link

ecdsa commented Feb 16, 2017

@prusnak I am running the latest setuptools, see above

@prusnak
Copy link
Contributor

prusnak commented Feb 16, 2017

Do you have Cython installed? Preferably also latest

@ecdsa
Copy link

ecdsa commented Feb 16, 2017

@prusnak I have Cython-0.25.2, installed with pip3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants