question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how do I use modules that I've installed from `pip`?

See original GitHub issue

A big part of the benefit of a Python to JavaScript transpiler is the ability to use libraries from the Python ecosystem. Obviously, we won’t be able to use libraries that do I/O or depend on C modules, but things like https://pypi.python.org/pypi/deferred or https://pypi.python.org/pypi/attrs or https://pypi.python.org/pypi/six or https://pypi.python.org/pypi/Automat are important to be able to use code consistently between clients and servers. Looking through the documentation, I don’t see any way to go from a Python virtualenv with all these things installed to a redistributable bundle.

I don’t know Transcrypt well enough to know if this is a feature request or just a documentation request, but I would like to do it.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
JdeHcommented, Apr 10, 2016

Hi, thanks for you feedback. Transcrypt is primarily meant to be able to the Python syntax and class base inheritance to build readable, maintainable applications on top of the JS library world. Some elaboration given at http://www.transcrypt.org/introduction.html. It is a niche project situated somewhere between Pypyjs (fully rooted in Python ecosystem) and Brython (largely rooted in Python ecosystem) on one hand and e.g. RapydScript (fully rooted in JS ecosystem, a tin layer on top of JS, no multi inher, no bound func. ptrs)

So it primary design goal wasn’t cooperation with Python libs but seamless coop with JS libs. Having said that, the project got much further in the direction of a complete Python3.5 implementation than I initially expected. It also lacks some essentials, like metaclasses. Nevertheless it should be able to cooperate with a large set of Python libs, probably with small modifications.

I have not yet looked into that, the priority in development currently lies with further adaptation to the JS world by the addition of sourcemaps.

As I proof of concept I did a port of a very tiny part of NumPy, called Numscrypt. It can be pip installed and used from both CPython and Transcrypt. I both installed it without any environment manager and under miniconda (on Linux), which both proved to be unproblematic.

So in principle it’s possible to have a pure Python library installed “in the usual way” and use it both from CPython and Transcrypt.

Admittedly it would be a great benefit if more pure Python libs could be used from Transcrypt. Given the fact that many people use virtualenv or something like it, it would also clearly be a great benefit if it would cooperate with that.

However that’s something I have not looked into at all. Two things will be required:

  • Transcrypt has to somehow cooperate with these environment management tools. I honestly don’t know what that takes at the moment, but it is a requirement.
  • Transcrypt has to be complete enough to indeed run the library in question. That’s the main hurdle. However complete it may become, it will always remain a subset of CPython. This was a deliberate design choice, speed is favoured over completeness, this tool should generate truly useable JS code that runs fast enough to drive production sites.

So: Once I’m done with the sourcemaps, I’ll probably do some experiments, to find out if it’s feasible to make some important pure Python libs available to Transcrypt using a standard installation procedure and something like virtualenv. The outcome may be one of both:

  1. It may be doable with sacrificing the speed of compactness of Transcrypt code. In that caseit what’s necessary to do this, will certainly be implemented, because indeed the benefits are worthwhile.
  2. It may not be doable without bloating Transcrypt, making the generated JS less readable or bulky. In that case Trancrypt will stick with its orignal design goals: lean and mean.

So unfortunately for now I’ll have to refer to PyPyJs (experimental) and Brython (fully functional) if you need a more complete support of Python libs.

An alternative I have not yet mentioned is to port certain Python libs to thin layers on top of comparable JS functionality.

All in all, with the first version out, there’s still a lot to do. Sorry I cannot give you a more conclusive message at the moment, but this is how it stands…

Kind regards Jacques

0reactions
JdeHcommented, Apr 14, 2016

Transcrypt currently only compiles to JS5. JS6 support will be added with the Python 3.6 compatible version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to install modules with PIP (and fix it when it fails) - Medium
How to use PIP. Installing modules to python is painfully easy. Simply open up your terminal: Windows — Command Prompt (CMD) ...
Read more >
Build a Python Module and Share it with Pip Install - YouTube
What if everyone could use and install your authored Python package just by typing pip install and your module name at the end...
Read more >
How to download and install Python Packages and Modules ...
This tutorial covers how to download and install packages using pip. Pip comes with newer versions of Python, and makes installing packages ......
Read more >
python - Unable to import a module that is definitely installed
I've just tried this every which way -- setup.py, easy_install, pip -- from pypi and the repo, but I can't get it to...
Read more >
How to find Python List Installed Modules and Version using ...
1. Using help() function (without pip): ... The simplest way is to open a Python console and type the following command… ... This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found