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

Output file still want to import files #20

Closed
lborgman opened this issue Jan 16, 2021 · 20 comments
Closed

Output file still want to import files #20

lborgman opened this issue Jan 16, 2021 · 20 comments

Comments

@lborgman
Copy link

Please notice that I do not normally use python! So I do not know the import system at all.

I tried to make a single python file for a youtube-dl case:

`stickytape %mypar%/youtube_dl/mytest.py --add-python-path . --output-file st-temp.py`

The output file works in the same directory where it is written. But it still imports other files (which I to my surprise noticed when I tried to move it).

The file mytest.py looks like this (this file is mostly just copied from main.py):

from future import unicode_literals

import sys

import os.path
path = os.path.realpath(os.path.abspath(file))
sys.path.insert(0, os.path.dirname(os.path.dirname(path)))

import youtube_dl

if name == 'main':
sys.argv = [sys.argv[0], "-g", "https://www.youtube.com/watch?v=N5xyr1_DhpA" ]
youtube_dl.main()

It is import youtube-dl that is the still there. (And that is of course just a start of the imports I want to avoid.)

(There is another problem too. The from __future__ import unicode_literals does not work. Moving it to the top of the output file fixes this problem.)

@mwilliamson
Copy link
Owner

This is likely because you're modifying sys.path as part your script, so stickytape won't be able to find youtube_dl (assuming it's not otherwise on your Python path). As a general rule in Python programming, I'd suggest avoid directly manipulating sys.path in a script. Stickytape supports adding specific paths to the Python path using the --add-python-path argument, as documented in the README.

@lborgman
Copy link
Author

@mwilliamson Thanks. I changed to that. (Maybe mention this in the docs?)

Now I get much more complicated errors. I think I will look at them and see if I understand anything. And probably file a new bug report.

(If you prefer I can give more detailed instructions here. So you do not have to wait for my probably slow analysis.)

@mwilliamson
Copy link
Owner

Closing for now, but feel free to reopen if you find any issues.

@lborgman
Copy link
Author

Thanks, but please reopen. I can't get this to work. (I did send you a mail message a few days ago where I told you this and asked for some help.)

@mwilliamson
Copy link
Owner

Could you describe the problem you're having?

@lborgman
Copy link
Author

lborgman commented Jan 24, 2021

As I said I normally do not explicitly use python. So my setup of python might be broken. I really do not know.

To investigate this I switched from using Windows 10 cmd shell to the Ubuntu subsystem that now comes with Windows 10. I normally do not use Ubuntu (or any Linux-variant) so I struggled a bit with the setup again. After consulting my friend Internet I think I finally got the setup complete by using

sudo apt-get update and sudo apt-get dist-upgrade

A surprisingly 300 MB update.

After moving from __future__ import unicode_literals to the top of the stickytape output I now get the error below. (There may be something wrong with PYTHONPATH. I get a bit lost here.)

`# python b.py
Traceback (most recent call last):
File "/tmp/tmpqc6wj4gm/youtube_dl/extractor/init.py", line 4, in
from future import unicode_literals
ModuleNotFoundError: No module named 'youtube_dl.extractor.lazy_extractors'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "b.py", line 1640, in
import youtube_dl
File "/tmp/tmpqc6wj4gm/youtube_dl/init.py", line 43, in
from .extractor import gen_extractors, list_extractors
File "/tmp/tmpqc6wj4gm/youtube_dl/extractor/init.py", line 9, in
import io
File "/tmp/tmpqc6wj4gm/youtube_dl/extractor/extractors.py", line 4, in
ModuleNotFoundError: No module named 'youtube_dl.extractor.abc'`

@mwilliamson
Copy link
Owner

I'm afraid I can't help without being able to see the source code, or other ways of reproducing the error. If you could provide minimal reproduction steps, then I'll take a look if I get a chance.

@lborgman
Copy link
Author

I think I have given you all the info needed to reproduce it. Could you please tell me what you are missing?

@mwilliamson
Copy link
Owner

I think I have given you all the info needed to reproduce it. Could you please tell me what you are missing?

I don't think you've shared the code that you're trying to use stickytape on. If you could share that code, and the command you're using, then that would help.

@lborgman
Copy link
Author

The code I want to use stickytape on is in the repository below. (With the small addition I mentioned in the beginning.)

https://github.com/ytdl-org/youtube-dl

@mwilliamson
Copy link
Owner

Could you post the code that you're using? You posted some code in the original issue, but later said that you'd changed it, so I don't know what code you're using now. Also, could you post the command you're using?

@lborgman
Copy link
Author

lborgman commented Jan 24, 2021

youtube-dl/youtube_dl/mytest.py:

##### Copied from __main__.py

from __future__ import unicode_literals
import sys
import youtube_dl

if __name__ == '__main__':
    print()
    print(f"Arguments count: {len(sys.argv)}")
    for i, arg in enumerate(sys.argv):
        print(f"Argument {i:>6}: {arg}")
    sys.argv = [sys.argv[0], "-g", "https://www.youtube.com/watch?v=N5xyr1_DhpA" ]
    youtube_dl.main()

In youtube_dl:
stickytape mytest.py --add-python-path .. --output-file b.py

@mwilliamson
Copy link
Owner

It looks like there's a few different imports in youtube-dl that stickytape doesn't handle correctly. I'll take a look at fixing them if I get a chance, but I don't know when that will be.

@lborgman
Copy link
Author

Please reopen. This is a blocking issue for me.

@lborgman
Copy link
Author

It looks like there's a few different imports in youtube-dl that stickytape doesn't handle correctly. I'll take a look at fixing them if I get a chance, but I don't know when that will be.

That sounds very good. It looks a bit complicated.

I am trying to help to solve some accessibility issues with this. It has been on my to-do list for long. And I hoped that this could be a way. So I am looking forward to your replies.

@mwilliamson
Copy link
Owner

This is just a spare time project for me, so I wouldn't hold your breath! Depending on your use-case, you might well be better off using something else: for instance, using PyInstaller, or using the single-file youtube-dl download.

@lborgman
Copy link
Author

I need a single python file. And it should be as small as possible. I don't believe there is something like it from youtube-dl. (I need to import this to Brython.)

If you have some thoughts about what goes wrong I can perhaps look into it.

@mwilliamson
Copy link
Owner

The latest version of stickytape resolves at least some of the issues in using youtube-dl. I haven't tried your specific example though.

@lborgman
Copy link
Author

Thanks, that sounds very nice. I will have a look as soon as I can.

@lborgman
Copy link
Author

lborgman commented Jan 28, 2021

Many thanks! I took a deep breath, updated python to 3.9, updated stickytape. It did not work in Windows 10 cmd shell.

Took a much deeper breath, updated Windows WSL, updated Ubuntu for WSL to 21.04, updated its python to 3.9, etc.

The output file worked (in Ubuntu bash).

This was a very essential step in what I am trying to do. Now over to the people at Brython to get some advice there.

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