Git Product home page Git Product logo

Comments (21)

kayhayen avatar kayhayen commented on September 26, 2024 1

@artem3k with my fix, workarounds should not be necessary anymore, but all forms are supposed to work. Of course, specifying the path indeed avoids the problematic code, but I am not sure your variant does it, anyway, changing the code is never the preferred solution in Nuitka, we want to be 100% compatible with these kind of packages.

from nuitka.

kayhayen avatar kayhayen commented on September 26, 2024

@KevinRodriguez777 can you confirm this? dotenv rings a bell though, probably it's complaing about a lack of config file there.

from nuitka.

KRRT7 avatar KRRT7 commented on September 26, 2024

@KevinRodriguez777 can you confirm this? dotenv rings a bell though, probably it's complaing about a lack of config file there.

it's failing here https://github.com/theskumar/python-dotenv/blob/d6c0b9638349a7dd605d60ee555ff60421c1a594/src/dotenv/main.py#L302-L306
it's not a config file issue, it's a problem when using load_dotenv()

from nuitka.

KRRT7 avatar KRRT7 commented on September 26, 2024

i could PR dotenv and do something like this

if usecwd or _is_interactive() or getattr(sys, 'frozen', False):
        # Should work without __file__, e.g. in REPL or IPython notebook.
        path = os.getcwd()
elif "__compiled__" in globals():
        # For Nuitka compiled programs, use the directory of the main script
        path = os.path.dirname(sys.executable)

or we could handle it from the YAML or nuitka side, what do you think?

from nuitka.

kayhayen avatar kayhayen commented on September 26, 2024

I think __compiled__.containing_dir is the better choice, it works independent of modes, e.g. app bundles, module mode, onefile, etc. and is preferable to manual guessing. I added it only recently.

.. important::

   What you should **not** do, is use the current directory
   ``os.getcwd``, or assume that this is the script directory, e.g. with
   paths like ``data/``.

   If you did that, it was never good code. Links, to a program,
   launching from another directory, etc. will all fail in bad ways. Do
   not make assumptions about the directory your program is started
   from.

In case you mean to refer to the location of the ``.dist`` folder for
files that are to reside near the binary, there is
``__compiled__.containing_dir`` that also abstracts all differences with
``--macos-create-app-bundle`` and the ``.app`` folder a having more
nested structure.

.. code:: python

   # This will find a file *near* your app or dist folder
   try:
      open(os.path.join(__compiled__.containing_dir, "user-provided-file.txt"))
   except NameError:
      open(os.path.join(os.path.dirname(sys.argv[0]), "user-provided-file.txt"))

What is the original code like from dotenv there?

from nuitka.

KRRT7 avatar KRRT7 commented on September 26, 2024
        while frame.f_code.co_filename == current_file or not os.path.exists(
            frame.f_code.co_filename
        ):
            assert frame.f_back is not None
            frame = frame.f_back
        frame_filename = frame.f_code.co_filename
        path = os.path.dirname(os.path.abspath(frame_filename))

the problem is that it was failing due to this. the source is linked above

from nuitka.

kayhayen avatar kayhayen commented on September 26, 2024

Oh, os.path.exists(...co_filename) is going to be false a lot for Nuitka. I guess, it wants to find the frame upwards, that lives in a different file.

inspect.getmodule(os.path.basename.code)
<module 'posixpath' from '/usr/lib/python3.10/posixpath.py'>

That makes me assume this would be a good replacement:

while inspect.getmodule(frame.f_code) is inspect.getmodule(sys._getframe()):
   frame = frame.f_back

That is however only beauty I guess.

With the existence check, it probably wants to get rid of import bootstrap ones, which I think are better done with a .startswith() on the module __name__ maybe. So

not os.path.exists(
            frame.f_code.co_filename
        )

could likely be replaced with

inspect.getmodule(frame.f_code).startswith("importlib"

Multi-line strings are a bit difficult in yaml, but doable with the | notation. So far, we use them only for replacement values, but maybe there is an example how to use it for the key in the replacement_plain dict.

from nuitka.

c469591 avatar c469591 commented on September 26, 2024

Hello!
Although I don't quite understand what you are discussing, may I ask if my question has already found a solution?
Or what should I do now to solve this problem?
Thank you.

from nuitka.

artem3k avatar artem3k commented on September 26, 2024

Hello!

You can temporarily bypass using find_dotenv.

    if dotenv_path is None and stream is None:
        dotenv_path = find_dotenv()

load_dotenv() -> no work
load_dotenv('.env') -> work

from nuitka.

c469591 avatar c469591 commented on September 26, 2024

hi
@artem3k
Where should I add the judgment code you mentioned? Adding the judgment code as you said in my code will cause errors.
NameError: name 'dotenv_path' is not defined
thank

from nuitka.

kayhayen avatar kayhayen commented on September 26, 2024

Please allow me to criticize this issue. There are not even pip package names provided, that are required to run the example. When I do it, I get an error like this:

  File "C:\Users\kayha\repos\Py2C\Mini2.py", line 28, in login
    driver = webdriver.Edge(EdgeChromiumDriverManager().install(), options=option)
TypeError: WebDriver.__init__() got multiple values for argument 'options'

The example is asking choices, I do not want prompts in minimal examples, I want straight out errors, that are unique to the code.

from nuitka.

kayhayen avatar kayhayen commented on September 26, 2024

For the dotenv part, I updated our workaround to their new (bad) code. Previously they insisted on package directories to exist (which they do not with compiled code in all cases), and now they want filenames of Python files to exist, which they definitely do not with Nuitka. With that, I am getting the same error when selecting Edge as with the example script.

from nuitka.

kayhayen avatar kayhayen commented on September 26, 2024

Thanks for your report, this is fixed on the factory branch, which is a development version under rapid development. You can try it out by going here: https://nuitka.net/doc/factory.html

Feedback if this is working is very welcome, just please do not share plans of doing it, but rather confirmations or denials of it working.

from nuitka.

c469591 avatar c469591 commented on September 26, 2024

@kayhayen
Hello, I have used this command to update to the development version.
python -m pip install -U --force-reinstall "https://github.com/Nuitka/Nuitka/archive/factory.zip"
The displayed version is
Successfully installed Nuitka-2.2rc2 ordered-set-4.1.0 zstandard-0.22.0
I use this command to package the exe.
nuitka --standalone --show-memory --show-progress --follow-import-to=need --output-dir=o --nofollow-imports test.py
An error occurred.
log.log

from nuitka.

artem3k avatar artem3k commented on September 26, 2024

@c469591 Sorry, I misled you. The code above is a snippet from the dotenv code. A temporary solution is simply to specify the path load_dotenv('.env')

from nuitka.

kayhayen avatar kayhayen commented on September 26, 2024

@c469591 that was a regression of factory, that I fixed only now, please retry

from nuitka.

c469591 avatar c469591 commented on September 26, 2024

@kayhayen
Succeeded, the exe file can now run normally.
However, the time it takes to package into an exe file is particularly long, taking nearly 10 minutes. Is there a way to shorten the packaging time for exe files?
thank

from nuitka.

kayhayen avatar kayhayen commented on September 26, 2024

Yes, but this is not a personal support thread.

from nuitka.

c469591 avatar c469591 commented on September 26, 2024

@kayhayen
Could you please tell me if individual support services require the purchase of a subscription? Or where should I inquire about it?
thank

from nuitka.

kayhayen avatar kayhayen commented on September 26, 2024

@c469591 https://nuitka.net/doc/commercial.html and there is a form if it doesn't answer your questions

from nuitka.

kayhayen avatar kayhayen commented on September 26, 2024

This part of the 2.1.3 release I just made.

from nuitka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.