I am doing a small game in which I use "from tl.testing.thread import ThreadJoiner" to execute threads when executing from console the program as such works but when creating the executable with the help of cx_freeze I have the problem that when executing the program I get an error respect tl tells me that the module tl is not found and the program is not executed.
the error is this:
C:\Users\The.hacker\AppData\Local\Programs\Python\Python36-32\lib\site-packgages\cx_freeze\initscripts\_startup_.py",line 14,in run
module.run()
file:
C:\Users\The.hacker\AppData\Local\Programs\Python\Python36-32\lib\site-packgages\cx_freeze\initscripts\Console.py",line 26,in run
exec(code,m._dict_))
file "the_last_warrior",line 11,in <module>
Modulenotfounderror:no module named tl
on line 11 is the from tl.testing.thread import ThreadJoiner
now the image:
my file main is "the_last_warrior.py"
from tkinter import *
from tkinter import ttk
import tkinter as tk
import tkinter
from tl.testing.thread import ThreadJoiner
import threading
import datetime
from threading import Thread
has more than 1600 lines,In itself, how would the correct import of this module be? (from tl.testing.thread import ThreadJoiner)
picture of error:
console_vs_exe.jpg
After trying many things, I solved by copying the package directly from the folder "Lib \ site-packages" my package "tl" and paste it into the Lib folder of my program already ready after using the setup.py the program executes runs as I expected.
Related
My python app runs fine when I run it through my IDE (Pycharm), without any problems.
But as soon as I create an executable (via the command line:
"pyinstaller --onefile -w main.py"), and then I launch the executable, I get this message:
I have installed PIL via the Pillow module, because PIL directly did not work.
My script starts with all the dependencies:
from PIL import Image as Img,ImageTk
import imageio
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
import os
All the python scripts and folders and environment are set within the project root folder.
Why is this happening and what can I do to create an executable that actually works?
Follow-up from earlier question here
Running a locust (locust.io) script from the command line.
locust calls main.py which has the following imports:
from locust import HttpUser, between, task
from StreamLoader.stream_generator import * # thought this brings in everything
Packer.py has these imports:
from multipledispatch import dispatch
from PackedItem import PackedItem
StreamGenerator.py has:
import hashlib
from StreamLoader.Packer import Packer
from aes_encryption import AesEncryption
I now see a missing module error:
File "C:\Users\guyl\PycharmProjects\engine-load-tests\engine_load_tester_locust\main.py", line 2, in <module>
from StreamLoader.stream_generator import *
File "C:\Users\guyl\PycharmProjects\engine-load-tests\StreamLoader\stream_generator.py", line 2, in <module>
from Packer import Packer
ModuleNotFoundError: No module named 'Packer'
For clarity, I am running the code from locust which calls the Python code as depicted here.
Here's the file structure:
Placed periods (full stops) before the package names in the import statements.
I then was able to run the locust script from within PyCharm.
Running from the DOS shell, I was able to accomplish the same by first running
<project directory>\venv\Scripts\activate
On my Lego ev3 robot my current project is to add the pygame joystick module into my robot and get it up working so I can use my PS1 remote to control Lego ev3 robot. I have put the WHOLE folder from site-packages in python onto my robot and I am not getting the error no module named pygame but I am getting the error no module named pygame.base and many others like no module named pygame.constants after it.
I have looked at the robot's logfile which shows the errors that the code might have on a file that comes whenever you run the robot. I have tried running the robots python file via my computer and I have also tried it via the robot itself both lead to the same error.
I have tried running the same pygame on my computer with my own python games with pygame that I have tried creating and the games on that work fine with no importing errors what so ever.
I have already tried looking into the pygame's __init__.py code where the error is coming from and the code where all the errors are coming up looks something like this:
The code in the pygame's __init__.py has some imports where I think the error is coming from:
from pygame.base import *
from pygame.constants import *
from pygame.version import *
from pygame.rect import Rect
from pygame.compat import geterror, PY_MAJOR_VERSION
from pygame.rwobject import encode_string, encode_file_path
import pygame.surflock
import pygame.color
Color = color.Color
import pygame.bufferproxy
BufferProxy = bufferproxy.BufferProxy
import pygame.math
The actual output from when I run the code either on my robot or via visual studio code is:
Traceback (most recent call last):
File "/home/robot/drive/main.py", line 10, in <module>
File "/home/robot/drive/pygame/__init__.py", line 136, in <module>
ImportError: no module named 'pygame.base'
the picture
Python has list sys.path with folders in which it looks for modules. There is folder site-packages so import can find pygame in site-packages/pygame and pygame.base in site-packages/pygame/base
If you moved pygame to folder /home/robot/drive then you have to add it to sys.path before import
import sys
sys.path.append('/home/robot/drive/')
import pygame
and then it can find pygame in /home/robot/drive/pygame and pygame.base in /home/robot/drive/pygame/base
Normally Python looks for modules in folder in which you run code so import pygame can find /home/robot/drive/pygame without adding folder to sys.path but __init__.py runs in folder /home/robot/drive/pygame so from pygame.base import * will look for /home/robot/drive/pygame/pygame/base and there is to many pygame in path. If it would use relative path from .base import * then it would search in /home/robot/drive/pygame/./base which means /home/robot/drive/pygame/base so it would use correct path and it would work without adding folder to sys.path
I have a python script that i have to import all these modules, which some of them require downloading:
import datetime
from dateutil import parser
from tkinter import filedialog
import tkinter
import mailbox
import pprint
import json
import urllib.request
from tkinter import *
Is there a way, using py2exe, i can convert the script into a windows executable. If so, how?
To simplify the procedure, you will want to have all your modules already downloaded. This can be accomplished with a simple "pip install " from command prompt. Then it is as simple as writing and running a setup.py file - detailed directions for how to do this can be found here.
I'm seeing weird behavior that I don't understand, so I'm turning to the experts here on SO for help. I have looked at similar questions, without finding anything that looked helpful.
I'm writing a program that imports two custom modules.
If I run the main program using the cli "./ld_config_automation.py" I get the following error:
laptop$ ./ld_config_automation.py
Traceback (most recent call last):
File "./ld_config_automation.py", line 34, in <module>
from modules.networkcomponent import NetworkComponent
File "/path/to/pprograms/ssh_telnet_automation/modules/networkcomponent.py", line 7, in <module>
import pexpect
ImportError: No module named pexpect
However, if I run the main program using the cli "python ld_config_automation.py" everything works fine and the program runs.
My main program uses the following import statements.
import sys
import getopt
from modules.networkcomponent import NetworkComponent
from modules.recordclass import Record
The module I'm having trouble with "NetworkComponent" uses the following import statements:
import re
import pexpect
Also, if I remove import pexpect from the NetworkComponent module it works as expected without python in front (up to when it has to use pexpect. of course). So it doesn't seem to be a problem with importing modules, as re works ok, just not pexpect.
I'm developing this on mac os X but will implement on CentOS.