Error after executing .py file exe in pyinstaller

Asked 1 years ago, Updated 1 years ago, 82 views

Error after executing .py file exe in pyinstaller.

(base) C:\Users\genki> C:\Users\genki\Downloads\dist\test01.exe
Traceback (most recent call last):
  File "test01.py", line 7, in <module>
NameError: name 'get_ipython' is not defined
[9180] Failed to execute script test01

Translate the above error statement

"Traceback (last last call):
File "test01.py", line 7
NameError: name 'get_ipython' not defined
[9180] Failed to run script test01
US>"
Search for "NameError: name 'get_ipython' is not defined" and try to resolve it.
It deepened the chaos...it was posted on this site.
Professor, please.

"I have attached the "".py file"" below."

#!/usr/bin/env python                               
# coding —utf-8                             
                                
# In [1]:                                
                                
                                
get_ipython().system('pip3install-U selenium')                                
                                
                                
# In[2]:                                
                                
                                
get_ipython().system('pip3install webdriver_manager')                              
                                
                                
# In[3]:                                
                                
                                
from selenium import webdriver                              
from webdriver_manager.chrome import ChromeDriverManager                                
                                
                                
# In[4]:                                
                                
                                
driver = webdriver.Chrome (ChromeDriverManager().install())                              
driver.get('https://scraping-for-beginner.herokuapp.com/login_page')                                
                                
                                
# In [5]:                                
                                
                                
elem_username=driver.find_element_by_id('username')                               
elem_username.send_keys('imanishi')                             
                                
                                
# In [ ]:                                

·Comment out was executed.(I also understand the meaning)
·"Write from IPython import get_ipython in the py file and move it with python"
 It says so, but is the place below acceptable?

 from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from IPython import get_ipython

Also,
"Try running an unconverted .py file in Python or IPython" means
Is the following method acceptable?

 (practice) C:\Users\genki\Downloads>python                      
Python 3.9.4 (default, Apr 9 2021, 11:43:21) MSC v.1916 64bit (AMD64):: Anaconda, Inc. on win32                        
Type "help", "copyright", "credits" or "license" for more information.                      
>>>test04.py                       
 (practice) C:\Users\genki\Downloads>IPython                             
Python 3.9.4 (default, Apr 9 2021, 11:43:21) [MSC v.1916 64bit (AMD64)]                               
Type 'copyright', 'credits' or 'license' for more information                               
IPython 7.22.0 -- An enhanced interactive Python.Type '?' for help.                                
                                
In[1]: test04.py                               

python3 pyinstaller

2022-09-29 22:52

1 Answers

You will not need those two get_ipython().system(...) lines.
Comment out or delete before converting to .py or processing with PyInstaller.

The function has only been converted from !pip3install... in JupiterLab, which should be unnecessary in JupiterLab if it runs only once in the environment.

Please refer to this article.
When I exported .py data in JupiterLab, "NameError: name 'get_ipython' is not defined"
Below is an excerpt.

After coding on JupiterLab, it worked fine, so I wrote it out in the .py file...

There seems to be a problem with the 7th line, so if you look at it,

Huh? On JupiterLab, it must have been ↓↓!

!pip install selenium

"When I commented out the ""!pip install 〇 」"" part on JupiterLab, wrote it out in "".py"" and executed it…it worked⤴⤴

"

If the line is not !pip3install... and is required for each operation, this is probably the case.
I want to move files exported from JupiterLab locally

NameError: name 'get_ipython' is not defined, so get_ipython is not defined.

At the command prompt, I typed python and dragged the py file.

However, I think there are two ways to solve this problem.

  • python instead of python
  • From IPython import get_ipython in the py file and move it with python

Alternatively, os.system(command) or of the subprocess module would be better than above.

Support for postscripts:

You do not need to add from IPython import get_ipython because you do not need the current get_ipython
However, if you really need it, you must import it before the line to be called.

"Try to run an unconverted .py file in Python or IPython" means copying the contents of the file or specifying the script filename (full path unless it is the current folder) in the parameters at Python startup, such as python test04.py.


2022-09-29 22:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.