exit not defined when compile python to binary using pyinstaller on linux - python

I have a socket server python script and it runs good on linux, but when compiled to binary on Linux using pyinstaller, it runs into wired situations says
File "<string>", line 426, in <module>
File "<string>", line 49, in __init__
NameError: global name 'exit' is not defined
environment:
Linux 2.6.32, python2.6.6, pyinstaller 2.0
here is a simple test script that could recreate this error
program:
exit.__class__
compile commands:
pyinstaller.py -F --noconsole --out=/output_folder/ /source/path
which expect to print out:
<class 'site.Quitter'>
hope someone could give me a clue, a shared library thing?

solved, explicitly use sys.exit(1) to skip this.

Related

How to run a Python script in VSCode using the same path of the script? (otherwise it can't find an input file located in the same folder)

I have this Python code: https://github.com/andreagrandi/aoc_2019/tree/master/aoc
which runs perfectly from the terminal (Python 3 required) if I do for example: python aoc_03.py
But if I try to run it from VSCode, taking advantage of the Python extension and integration, I get this error:
(aoc) ➜ advent_of_code_2019 git:(master) /Users/andrea/.virtualenvs/aoc/bin/python /Users/andrea/Documents/advent_of_code_2019/aoc/aoc_03.py
Traceback (most recent call last):
File "/Users/andrea/Documents/advent_of_code_2019/aoc/aoc_03.py", line 70, in <module>
with open('aoc_03_input.txt', 'r') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'aoc_03_input.txt'
My guess is that when invoked from VSCode, the script is run from a different path, so it cannot find the file aoc_03_input.txt which is located in the same folder of the script.
How do I tell VSCode to run my script from the /Users/andrea/Documents/advent_of_code_2019/aoc/ folder, so that it will be able to find my input file?
Thanks
Actually, I should have tried more before asking this question, because I just found the solution, but at this point I will write it here in case it can be useful to anyone:
If I change the path in this way:
with open('./aoc_03_input.txt', 'r') as file:
The file is being open correctly when I run the code in VSCode and when I run it from the terminal. Tested under OSX (but it should work under Linux too. Not sure about Windows).

How to run a python script taking arguments with blender?

I have a script I want to run within blender to generate AO maps (script was given to me and the source guarantees it works).
I try to run the script as follows:
blender --background --python /opt/ff/product_builder/furniture_builder/generate_ao_maps.py --input_dir /tmp/test.obj --output_dir /tmp/test.png --mode ao
Which produces:
AL lib: (EE) UpdateDeviceParams: Failed to set 44100hz, got 48000hz instead
found bundled python: /usr/share/blender/2.79/python
Traceback (most recent call last):
File "/opt/ff/product_builder/furniture_builder/generate_ao_maps.py", line 195, in <module>
main()
File "/opt/ff/product_builder/furniture_builder/generate_ao_maps.py", line 178, in main
args = parse_args()
File "/opt/ff/product_builder/furniture_builder/generate_ao_maps.py", line 21, in parse_args
return parser.parse_args(os.getenv(BLENDER_ENV).split(' '))
AttributeError: 'NoneType' object has no attribute 'split'
Error: File format is not supported in file '/tmp/test.obj'
Blender quit
If I run this same script without blender (but with the argument) it tells me:
Traceback (most recent call last):
File "/opt/ff/product_builder/furniture_builder/generate_ao_maps.py", line 5, in <module>
import bpy
ImportError: No module named bpy
What do I need to do to pass the parameters to the script and get it working?
You are seeing that error because your script is looking for the environment variable BLENDER_ENV, which is not on your system. I don't recognize BLENDER_ENV as a standard Blender related environment variable so it's probable that your friend added BLENDER_ENV to his or her environment.
Firstly, blender processes its cli args in the order they are given, so your example will start in the background, run a script, then set the input_dir... This will most likely not have the result you are after.
The problem with your script failing is that the arg passed to os.getenv() needs to be a string that is the name of a shell environment variable, if you are using bash you need to export the variable to put it into the environment before you start blender.
export BLENDER_ARGS="arg1 arg2"
blender -b myfile.blend --python myscript.py
If you are using a csh then use setenv BLENDER_ARGS "arg1 arg2"
Then in your py script, you use os.getenv('BLENDER_ARGS').split(' ')
Note that each shell instance is a separate environment, you need to set the variables in the same instance that starts blender.
You may also be interested in passing cli arguments to the script as explained in response to this question.

Error getting Scapy to work on Windows: "'module' object has no attribute 'ex_name'"

I'm trying to run a Python script that involves ARP sniffing and is apparently dependent on the Scapy library being present. I have absolutely no idea what I'm doing but I'm reasonably good at Googling, following directions, and copying/pasting. I have it up and running on my Mac, but I'm stuck on what I hope is the last hurdle in getting Scapy working on my Windows computer (which is ultimately the one that needs to be running this script).
I followed all of the instructions at http://www.secdev.org/projects/scapy/doc/installation.html#windows, except that I chose Python 2.7 and used the newer 2.7-compatible versions of everything listed there. I used “python setup.py install” (successfully, as best I could tell) on all installs except Pypcap and Libdnet, which I installed via the Exe as an Administrator as instructed.
Unfortunately, when I type "scapy" into the command prompt to test if it works, I get the following information & error message:
C:\scapy-2.3.1>scapy
INFO: Can't import python gnuplot wrapper . Won't be able to plot.
INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
Traceback (most recent call last):
File "C:\Python27\Scripts\\scapy", line 25, in <module>
interact()
File "C:\Python27\lib\site-packages\scapy\main.py", line 278, in interact
scapy_builtins = __import__("all",globals(),locals(),".").__dict__
File "C:\Python27\lib\site-packages\scapy\all.py", line 16, in <module>
from arch import *
File "C:\Python27\lib\site-packages\scapy\arch\__init__.py", line 79, in <module>
from windows import *
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 214, in <module>
ifaces.load_from_dnet()
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 173, in load_from_dnet
self.data[i["name"]] = NetworkInterface(i)
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 93, in __init__
self.update(dnetdict)
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 107, in update
self._update_pcapdata()
File "C:\Python27\lib\site-packages\scapy\arch\windows\__init__.py", line 118, in _update_pcapdata
win_name = pcapdnet.pcap.ex_name(guess)
AttributeError: 'module' object has no attribute 'ex_name'
Can anyone help me out? If you need more information please let me know.
I am running Windows 10.
Thanks in advance,
- Ethan
I had same problem.
To solve it, i downloaded dnet-1.12.win32-py2.7.exe
and pcap-1.1.win32-py2.7.exe.
You might want to try with Scapy's current development version (from the Github repository). Support for Windows has been updated recently and should work without the need of Libdnet.
If that's not the case, you should probably open an issue.
Try it with scapy3k. Install python3 (e.g. I use Anaconda 3.5), and WinPcap driver. You do not need dnet or pypcap. Install using pip install scapy-python3 or from http://github.com/phaethon/scapy

python subprocess.call() fails in Sublime Text 2 on this program

I've been stuck on a peculiar error for several hours, searching for solutions in Google and failing, probably because the problem is so specific, but it actually has broader implications, which is why I've been trying hard to fix it.
I am using Python 2.6 and can use the subprocess.call() to run a program called STAMP in the vanilla Python terminal, or even the iPython terminal as such:
>>>Import subprocess
>>>subprocess.call('stamp')
That works fine, but when I execute the same thing via sublime text 2 (ST2) using it's sublimeREPL plug-in for python or iPython (Tools>sublimeREPL>Python>...) it fails with the following error:
> Traceback (most recent call last): File "<stdin>", line 1, in
> <module> File "<string>", line 27, in <module> File
> "/usr/lib64/python2.6/subprocess.py", line 478, in call
> p = Popen(*popenargs, **kwargs) File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__
> errread, errwrite) File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child
> raise child_exception OSError: [Errno 2] No such file or directory
Which is the same error it gives when you call a program that is not installed on the system. It seems paradoxical that this error does not appear for any other installed programs/commands that I've tested other than 'stamp' (so you would think sublimeREPL is working fine), and yet running subprocess.call('stamp') does work in the native python terminal, as well as iPython (so you would think stamp is working/installed fine). The only clue I had in mind was that I had to install stamp using g++
Summary:
subprocess.call('stamp') works in a native python terminal
subprocess.call('stamp') does not work in ST2's sublimeREPL python terminal
subprocess.call() seems to work fine in both sublimeREPL or native python terminal
Extra info:
Python 2.6.3
Installation procedure for stamp:
Step 1: Install the GNU Scientific Library.
Download from http://www.gnu.org/software/gsl/
Add the 'include' and 'lib' directories to your PATH.
Step 2: Compile the STAMP code.
Use a command such as the following:
g++ -O3 -o stamp Motif.cpp Alignment.cpp ColumnComp.cpp \
PlatformSupport.cpp PlatformTesting.cpp Tree.cpp \
NeuralTree.cpp MultipleAlignment.cpp RandPSSMGen.cpp \
ProteinDomains.cpp main.cpp -lm -lgsl -lgslcblas
Note: if the GSL library is not in the PATH, add the appropriate
directories using the -L and -I compiler options.
Step 3: Test it out!
Converting my comment to answer form so that it's clearer that the problem was solved:
PATH is not set inside the sublimeREPL terminal. If you provide the full path to the stamp executable, subprocess.call will work fine.

may be python error!

Hi
I'm not familiar with python, I just want to check something so I tried to run a .py code in linux so I wrote :
./waf wifi-olsr-flowmon --plot
which is a .py program after that whatever I want to run just see these error:
/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/wscript: error: Traceback (most recent call last):
File "/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/.waf-1.5.16-e6d03192b5ddfa5ef2c8d65308e48e42/wafadmin/Utils.py", line 197, in load_module
exec(compile(code,file_path,'exec'),module.__dict__)
File "/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/wscript", line 32, in <module>
import cflags # override the build profiles from waf
ImportError: No module named cflags
I dont know what does it mean or why it happened, would you please tell me what is the problem .
may be I should add this note that even now that I don't want to run any .py code and just wana run .cc I can't do it and see this error always
Bests
It means that Python was unable to locate a module named cflags, but the code you're running tries to import it. Perhaps you need to set PYTHONPATH, or install the cflags module.
(Also, paragraphs are your friend.)

Categories

Resources