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

AttributeError: 'str' object has no attribute '_MEIPASS' #5797

Closed
aliada77 opened this issue May 3, 2021 · 4 comments · Fixed by #5850
Closed

AttributeError: 'str' object has no attribute '_MEIPASS' #5797

aliada77 opened this issue May 3, 2021 · 4 comments · Fixed by #5850
Labels

Comments

@aliada77
Copy link

aliada77 commented May 3, 2021

Description of the issue

I've used pyinstaller to convert my py to exe. App is working fine, all of the features are working ok except "pyperclip.copy".
Even I have no issue with "pyperclip.paste", only copying to clipboard.

Context information (for bug reports)

Whenever I use the command "pyperclip.copy(copy_clipboard)" to copy string to clipboard, it doesn't work instead I get following error:

Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter_init_.py", line 1884, in call
File "xxxxx.py", line 5107, in ctrl_c
File "pyperclip_init_.py", line 658, in lazy_load_stub_copy
File "pyperclip_init_.py", line 541, in determine_clipboard
File "pyperclip_init_.py", line 371, in init_windows_clipboard
File "PyInstaller\loader\pyiboot01_bootstrap.py", line 142, in init
File "PyInstaller\loader\pyiboot01_bootstrap.py", line 128, in _frozen_name
AttributeError: 'str' object has no attribute '_MEIPASS'

  • Output of pyinstaller --version: 4.3

  • Version of Python: 3.9.1

  • Platform: Windows 10

  • Did you also try this on another platform? No

  • try the latest development version, using the following command: I've tried but it failed to create exe file.

I've tried all suggested workarounds but couldn't fix this issue. I'm not an advanced programmer so it might be silly issue although I appreciate any help in this regard. Thanks!

@rokm
Copy link
Member

rokm commented May 3, 2021

This looks like the sys module is being shadowed by a string variable...

Are you assigning a string to a variable called sys anywhere in your code?

This seems to be reproducer and it seems to affect only frozen application:

# sys='whatever'  # uncomment to reproduce the problem
import pyperclip
pyperclip.copy('The text to be copied to the clipboard.')
print(pyperclip.paste())

@aliada77
Copy link
Author

aliada77 commented May 3, 2021

@rokm Thanks mate!
I changed sys variable to system_info afterwards it's working without any issue 🙏

@aliada77 aliada77 closed this as completed May 4, 2021
@bwoodsend
Copy link
Member

This is still a bug? That sys = "string" is somehow finding its way into:

frozen_name = os.path.join(sys._MEIPASS, os.path.basename(name))

... where it certainly doesn't belong.

@bwoodsend bwoodsend reopened this May 19, 2021
@rokm
Copy link
Member

rokm commented May 19, 2021

Yeah, this specific problem (overwriting sys or os with custom variable in global namespace) should be fixed if/when we move those ctypes classes and functions from pyboot01_bootstrap.py into a separate module (where the bound names of imported os and sys modules are module-scoped, and cannot be affected by global namespace variables).

The bootstrap script should be just a script, without any functions or classes that can be called or instantiated after the script itself has finished.

@bwoodsend bwoodsend added the bug label May 20, 2021
rokm added a commit to rokm/pyinstaller that referenced this issue May 20, 2021
The test attempts to trigger an error in PyInstaller's ctypes.CDLL()
wrapper, by using sys and os as string variables in the global
namespace.
rokm added a commit to rokm/pyinstaller that referenced this issue May 20, 2021
Move the ctypes hooks from bootstrap script into separate module
(pymod04_ctypes). The main motivation for this is to prevent the
modifications to global namespace from affecting the hook ctypes
hooks code; speficially, if user decides to use `sys` or `os` as
variables in the global namespace, that should not effect the
ctype hook function _frozen_name(), which treats `sys` and `os`
as names modules (which were bound to those names when the
bootstrap script was executing).

Fixes pyinstaller#5797.

This commit is a cleaned-up and modernized version of an earlier
commit from pyinstaller#3038 (daf60a6).

Co-authored-by: Hartmut Goebel <h.goebel@crazy-compilers.com>
rokm added a commit to rokm/pyinstaller that referenced this issue May 20, 2021
Move the ctypes hooks from bootstrap script into separate module
(pymod04_ctypes). The main motivation for this is to prevent the
modifications to global namespace from affecting the ctypes hooks
code; specifically, if user decides to use `sys` or `os` as
variables in the global namespace, that should not effect the
ctype hook function _frozen_name(), which treats `sys` and `os`
as names of modules (which were bound to those names when the
bootstrap script was executed).

Fixes pyinstaller#5797.

This commit is a cleaned-up and modernized version of an earlier
commit from pyinstaller#3038 (daf60a6).

Co-authored-by: Hartmut Goebel <h.goebel@crazy-compilers.com>
rokm added a commit to rokm/pyinstaller that referenced this issue May 20, 2021
Move the ctypes hooks from bootstrap script into separate module
(pymod04_ctypes). The main motivation for this is to prevent the
modifications to global namespace from affecting the ctypes hooks
code. Specifically, if user decides to use `sys` or `os` as
variables in the global namespace, that should not effect the
ctypes hook function _frozen_name(), which treats `sys` and `os`
as names of modules (which were bound to those names when the
bootstrap script was executed).

Fixes pyinstaller#5797.

This commit is a cleaned-up and modernized version of corresponding
commit from pyinstaller#3038 (daf60a6).

Co-authored-by: Hartmut Goebel <h.goebel@crazy-compilers.com>
rokm added a commit to rokm/pyinstaller that referenced this issue May 20, 2021
Move the ctypes hooks from bootstrap script into separate module
(pymod04_ctypes). The main motivation for this is to prevent the
modifications to global namespace from affecting the ctypes hooks
code. Specifically, if user decides to use `sys` or `os` as
variables in the global namespace, that should not effect the
ctypes hook function _frozen_name(), which treats `sys` and `os`
as names of modules (which were bound to those names when the
bootstrap script was executed).

Fixes pyinstaller#5797.

This commit is a cleaned-up and modernized version of corresponding
commit from pyinstaller#3038 (daf60a6).

Co-authored-by: Hartmut Goebel <h.goebel@crazy-compilers.com>
bwoodsend pushed a commit that referenced this issue May 22, 2021
The test attempts to trigger an error in PyInstaller's ctypes.CDLL()
wrapper, by using sys and os as string variables in the global
namespace.
bwoodsend pushed a commit that referenced this issue May 22, 2021
Move the ctypes hooks from bootstrap script into separate module
(pymod04_ctypes). The main motivation for this is to prevent the
modifications to global namespace from affecting the ctypes hooks
code. Specifically, if user decides to use `sys` or `os` as
variables in the global namespace, that should not effect the
ctypes hook function _frozen_name(), which treats `sys` and `os`
as names of modules (which were bound to those names when the
bootstrap script was executed).

Fixes #5797.

This commit is a cleaned-up and modernized version of corresponding
commit from #3038 (daf60a6).

Co-authored-by: Hartmut Goebel <h.goebel@crazy-compilers.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants