Py2exe not working for Python 3.5.1 - python-3.x

Is Py2exe just not supported for Python3 or is there something wrong with
build_exe my_script.py
The imports I made in my_script.py are as follows:
import os
import sys
import getpass
import hashlib
import platform
import base64
from cryptography.fernet import Fernet
But according to the documentation on Py2exe.org they say that they use an automatic module finder so you needn't worry about specific imports or whatever.
Can't figure out why I keep getting these errors

Unfortunately as of November 2017 there is no Python 3.5 support for py2exe.

Related

ModuleNotFoundError: No module named 'plotly' but it work from workspace

i have read all the posts related to this topic but i could not find the solution for my case.
In my ubuntu 20.04 I have installed plotly through the command:
pip3 install plotly
and if i launch python3 from command line and if i run:
import plotly.graph_objects as go
it works perfectly. But if i launch the same command from python script "test.py":
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import cgi
import cgitb
from datetime import date, timedelta
import datetime
import time
import numpy as np
import pandas as pd
import os
import calendar
import matplotlib
matplotlib.use('Agg')
import matplotlib.pylab as plt
import plotly.graph_objects as go
it returns the error log:
ModuleNotFoundError: No module named 'plotly'
Anyone can help me? many thanks
Ok, i resolved the issue by installing the module as a root user because in this way Python will try to search for the module’s name in the root directory and not in the usr one
thank you everyone

How to handle importing a package import if it doesn't exist

import os
import re
import fitz # requires fitz, PyMuPDF
import pdfrw
import subprocess
import os.path
import sys
from PIL import Image
In my case fitz doesn't exist since it needs PyMuPDF. Is there a way to tell python to download dependencies and install them if they don't exist?
I am new to python and learning a lot. Apologizes in advance
Using Python 3.9.4
Platform that I am developing on is macOS but will be deploying on Windows
Editor is VSCode
Using try-catch to handle missing package
Ex:
import subprocess
def install(package):
subprocess.call(['pip', 'install', package])
try:
import fitz # requires fitz, PyMuPDF
except:
install('fitz')
A better practice would be to handle this before your code is executed. Example: using a requirements.txt file with all the dependent packages. And running the file before code execution.

Terminal Command to install imported module of a module

Lets assume I have a module say utility.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from datetime import datetime
import os
import random
import sys
import threading
import numpy as np
import tensorflow as tf
.....
I'd like to import this in my drive.py. I have it saved in my local directory and have in my first line
from . import utility
Is that possible, to issue a command in terminal to find the non-local modules ( tensorflow, numpy, etc), and install them using pip?
Any workaround would be appreciated.
CS
If you mean that you'd like the command to parse the file's imports and install missing dependancies automatically, then no it is not possible.
There are modules that are not imported with the pip's package name. For example the package facebook-sdk is imported as import facebook, making impossible to deduct the package name from the import.

Python from Windows to Centos -> import msvcrt getch issue

I have a stupid question I think.
I have a script develloped on Windows but the goal is to run it on a Centos Server 7. The script work well on windows but not on Centos.
I have this error :
[root#114697 scripts]# python3.6 synch.py
Traceback (most recent call last):
File "synch.py", line 9, in <module>
from msvcrt import getch
ModuleNotFoundError: No module named 'msvcrt'
My script start with this :
from __future__ import division
import websocket
import thread
import time
import random
import sys
import json
import pymysql
import datetime
from time import ctime
from time import sleep
from msvcrt import getch
from pprint import pprint
import os
Seems msvcrt import getchcome from Microsoft ...
Can some one help to solve this problem please ?
Note : Python 3.6 is not involved, it was compiled in a clean way on the server.
Seems
Yoki
If you read the documentation for the msvcrt module, the first two sentences have this to say:
These functions provide access to some useful capabilities on Windows platforms. Some higher-level modules use these functions to build the Windows implementations of their services.
Since Centos Server 7 is not Windows, you will need to find an alternative approach to getch.
Solved ! I just remove
from msvcrt import getch
In fact in don't need to interact with the script on Centos ... it is a deamon :)

Why am I getting an AttributeError

I am trying to execute a command in linux when the file fast_dp.mtz is present. However, I get an attribute error.
import sys
import os
import time
import copy
import exceptions
import traceback
import subprocess
import os.path
from run_job import run_job
if(os.path_isfile('fast_dp.mtz')):
os.system('fast_ep sad=fast_dp.mtz')
Okay I figured out what I was doing wrong. Turns out that in Geany os.path is file command has an "_" (underscore) while my python 2.7 needed a "." (period). I just change that and the program ran fine.

Resources