Python Forum
can someone test the code for me
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
can someone test the code for me
#1
hi, I have this code;

try:
        import translators
except:
        import subprocess#for window 10
        subprocess.call("pip install translators --upgrade")
        import translators
        
import sys
if 'translators' not in sys.modules:
	print("not loaded")
else:
	print("loaded")
input("Press Enter to continue...")
the code is flawless if the file extension is .PY,
but if rename extension to .PYW the script somehow skipped or CTD,

can someone test it for me, it just me, or do all python user has the same problem?
Reply
#2
Is pythonw.exe in your PATH?

Try something less invasive like this.
with open("test.txt", "w") as file:
    file.write("This is a test")
Reply
#3
I don't use Windows, but I think a more robust way to write the subprocess call is
import sys
subprocess.call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'translators'])
Reply
#4
Hello. It is Jayson.

Try using debugging by inserting this at the top of the file...

`#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable() `
Reply
#5
Before somebody else asks,
my main problem is in "translators" packages, all script packages work fine with .pyw extensions, except the "translators" packages,
is this only on my PC or does your PC have the same problem too?

I edited code: #for tracing
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb
cgitb.enable()
print("step 1")#for tracing
try:
        import translators
except:
        import subprocess#for window 10
        subprocess.call("pip install translators --upgrade")
        import translators
print("step 2") #for tracing     
import sys
print("step 3") #for tracing  
if 'translators' not in sys.modules:
	print("not loaded")
else:
	print("loaded")

print("step 4") #for tracing  
input("Press Enter to continue...")
@deanhystad
create your code at the desktop, and the txt on the desktop too,

@Gribouillis
it indeed, but I tried to simplied the script so that my main problem is the priority

@jttolleson
I tried your code, but the result is the same, Crash to desktop
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 3,064 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  How to write test cases for a init function by Unit test in python? binhduonggttn 2 3,062 Feb-24-2020, 12:06 PM
Last Post: Larz60+
  How to write test cases by Unit test for database configuration file? binhduonggttn 0 2,511 Feb-18-2020, 08:03 AM
Last Post: binhduonggttn
  Mix-in class tree file not running the self test code. arjunsingh2908 3 2,921 Aug-14-2018, 05:46 PM
Last Post: arjunsingh2908
  code pattern to test if list has all the same Skaperen 5 3,380 Jul-25-2018, 06:09 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020