How to make this code work with py2exe - python

My code is like this:
from PIL import Image
from VideoCapture import Device
def cam_capture(usr):
try:
cam = Device()
cam.saveSnapshot('%s//intruder.jpg'%(usr))
del cam
except:
return
if __name__=='__main__':
cam_capture('aninda')
the problem is when i execute this code it works just fine but when i make an exe with
py2exe then it doesn't save the image..I am on windows 7 and using python 2.7

Related

How to install and download FF in code view? For Mac on Pycharm

Sorry for pretty stupid question, but I am noob in python.
I got the task to write code that installs and downloads Mozilla Firefox. I code on Mac.
For now I wrote the following:
import os
import urllib
import time
def download():
urllib.urlretrieve('https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US',
r'/Users/user/Downloads/Firefox 74.0.dmg')
def install():
os.system("cd /Users/user/Downloads/")
time.sleep(15)
os.system("hdiutil mount Firefox\ 74.0.dmg")
time.sleep(15)
os.system("open /Volumes/Firefox/")
time.sleep(15)
def main():
download()
install()
main()
But that's it. I received a lot of pop-up windows and I don't know how to move forward.
Maybe, someone know how execute it?

Python 3 script crash on lru_cache

I have raspberry pi acting as MFRC522 card reader. So far I have a script which worked on python 2.7, but when I tried to move to python 3, bizarre thing happened.
I used updated library for it: https://github.com/pimylifeup/MFRC522-python and adjusted my script accordingly
I installed pip3 and spidev
Here is where strange thing happens. If I run demo script from repo above in new folder it works, cool.
But if I put my previous script in the same folder it returns error as below. And after that if I try again to run demo script, same error occurs.
Moving both script to different folder, has the same effect. I can run demo only before my script. Doing that after, is impossible.
Error:
File "/usr/lib/python3.7/re.py", line 297, in <module>
#functools.lru_cache(_MAXCACHE)
AttributeError: module 'functools' has no attribute 'lru_cache'
My script:
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import time
import requests
import signal
import sys
import os
# some functions non related to MFRC522
reader = SimpleMFRC522()
while continue_reading:
try:
id, text = reader.read()
#print id
#print "---"
ver = query_server(id)
if ver == 1:
open_relay(5)
else:
#do something
finally:
time.sleep(0.5)
It's like folder is somehow tainted after firing my script, what am I missing?

Syntax error in importing a python package

I wanted to use the flask-opencv-streamer python package but cannot seem to find a workaround on how to import it.
If i use the example code at here: https://pypi.org/project/flask-opencv-streamer/#description , I will get an import error and in case if I change the '_' to '-',it gives syntax error.
from flask-opencv-streamer.streamer import Streamer
import cv2
port = 3030
require_login = False
streamer = Streamer(port, require_login)
# Open video device 0
video_capture = cv2.VideoCapture(0)
while True:
_, frame = video_capture.read()
streamer.update_frame(frame)
if not streamer.is_streaming:
streamer.start_streaming()
cv2.waitKey(30)

Pyinstaller creating exe file without pandas but still requires pandas import

I have a python code which runs fine when I run it through the cmd using python filename.py
But when I create exe file using pyinstaller the exe file opens and prints an exception I made(see at the bottom of the code) says no module name pandas.
Then, If I edit the code and import pandas and recreate the exe file it will work.
Does anyone have an idea?
I'm not using pandas in the code, and even PyCharm marks the import pandas line as redundant.
I have Windows 10 and anaconda installed.
Thank you
import csv,re
import os.path, time, datetime
import subprocess
import sys
try:
nameOfTitle= "name"
SName="S"
os.chdir(r'someaddress')
summaries_csv_path="summaries.csv"
HtmlPath='html/-----.htm'
HtmlPathNoDir='-----.htm'
HtmlPathNoDirC='----.htm'
HtmlPathNoDir='-----.htm'
sub="name"
headerH3="------"
dataWlCsv="raw.zip"
opRow = 0
sumRow = 0
col_num=0
innerCount=0
x = 0
headerList = list()
htmlfile = open(HtmlPath,"w")
execfile(r'some address')#header
readOp = csv.reader(open(r'some address.csv'),delimiter=',')
for row in readOp: # Read a single row from the CSV file
execfile(r'\some address.py')#logic
execfile(r'some address.py')#footer
except:
e = sys.exc_info()[1]
print("<p>Error: %s</p>" % e)
print "IN "+" MODUL!"

get the windows installation drive using python

How to detect the windows installation path or drive using python code ?
>>> import os
>>> os.environ['SYSTEMDRIVE']
'C:'
You can use GetWindowsDirectory via the ctypes library to get the location of the Windows folder, and then you can use os.path.splitdrive to get the drive letter. For example:
import ctypes
import os
kernel32 = ctypes.windll.kernel32
windows_directory = ctypes.create_unicode_buffer(1024)
if kernel32.GetWindowsDirectoryW(windows_directory, 1024) == 0:
# Handle error
else:
windows_drive = os.path.splitdrive(windows_directory)[0]
You can use the WINDIR enviroment variable.
os.environ['WINDIR']
Use this code to just get the letter, and nothing else:
import os
os.environ['WINDIR'].split(":\\")[0]
Example output:
>>> os.environ['WINDIR'].split(":\\")[0]
'C'

Categories

Resources