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
Related
So I have a hobby I like to do where I program automated systems that upload things to social media with no human input (and make a little side cash). But anyways, I've been trying to crack YouTube recently. YouTube has their own little way to upload videos automatically, but they watch over it INTENSELY. So, I found a work around using youtube_uploader_selenium, a cool little github project that allows you to upload as many videos as you want to YouTube through selenium firefox.
I know if I can get it to work, I can have a fully automated YouTube channel, however one single, important line of code doesn't work properly.
So the module is accessed via an import command in my main script
from youtube_uploader_selenium import YouTubeUploader
I was able to get that working, however when I did I got an error within the module from this line of code saying that selenium_firefox wasn't a valid pip/module.
from selenium_firefox.firefox import Firefox, By, Keys
So, I did some digging and found a PipInstaller script I could use.
import subprocess
import sys
py_exec = sys.executable
# ensure pip is installed & update
subprocess.call([str(py_exec), "-m", "ensurepip", "--user"])
# install dependencies using pip
subprocess.call([str(py_exec),"-m", "pip", "install", "selenium_firefox"])
That had some odd error involving Rust and the Cryptography pip so I decided to take a different approach. I tracked down the selenium_firefox github then downloaded the module from there. In the script I added a line which made it look for the module selenium_firefox in a certain folder where it was downloaded.
from typing import DefaultDict, Optional
from selenium_firefox.firefox import Firefox, By, Keys # problem code
from collections import defaultdict
import json
import time
from .Constant import *
from pathlib import Path
import logging
import platform
selenium_firefox.path.append(
"C:\\Program Files\\Blender Foundation\\Blender2.92\\2.92\\python\\PythonModules\\modules\\")
That <kinda???> worked. This is the error I currently have,
Traceback (most recent call last):
File "C:\Users\CLASSIFIED\Downloads\ASAS\zxxxs.blend\CLASSIFIEDSCRIPTNAME", line 5, in <module>
File "C:\Program Files\Blender Foundation\Blender 2.92\2.92\python\PythonModules\modules\youtube_uploader_selenium\__init__.py", line 2, in <module>
from selenium_firefox.firefox import Firefox, By, Keys
File "C:\Program Files\Blender Foundation\Blender 2.92\2.92\python\PythonModules\modules\selenium_firefox\__init__.py", line 1, in <module>
from .firefox import Firefox
ModuleNotFoundError: No module named 'selenium_firefox.firefox'
Error: Python script failed, check the message in the system console
I don't know where to go from here. The module within the module within the module has errored. This is what the script for the script that's currently producing this error.
from .firefox import Firefox
from .models import *
from .firefox_addons import *
from selenium_browser import *
My code
import random
import time
import pynput
import pynput.keyboard as kb
import pynput.mouse as ms
mouse = ms.Controller()
keyboard = kb.Controller()
I keep getting the error message:
Traceback (most recent call last):
File "c:\Users\user\Documents\visual studio code\notepadtest.py", line 1, in <module>
from pynput import *
ModuleNotFoundError: No module named 'pynput'
When i try to pip3 install it shows that it is already installed
how do i fix this?
Every module you download saves in site_package folder of python's folder, (dir:Python\Python39\Lib\site-packages).First open the folder where your python is installed (default directory is shown in the Image_1),then go to site_packages folder and copy your module(i-e 'pynput') from there.
There is also a site_pakages folder in project you make,like I noramaly use pycharm,as you can see in Image_2, I made a project with a name 'Hangman Game' and pycharm automatically made a site_pakages folder inside venu folder.You just have to paste your module (i-e 'pynput') there, run your program again and you will not get any error after that.
I want to make a file that is consisted of 3 python programs.
but, when I want to access one of the there files from one of them, it cant find the folder.
I made a init python file in it so python can recognize it as a module
my folder struct:
dlgo/
__init__.py
goboard_slow.py
gotypes.py
my goboard_slow:
from dlgo.gotypes import player
error:
Traceback (most recent call last):
File "C:\Users\asus\Desktop\dlgo\goboard_slow.py", line 2, in <module>
from dlgo.gotypes import player
ImportError: No module named 'dlgo'
Access as below:
from dlgo.gotypes import players
See here more info on "Guido's decision" on imports in python 3 and complete example on how to import in python 3.
maybe try from (filename) import (functionname)
Tl;dr:
from gotypes.py import player
when you specify path to a file, interpreter starts looking for it inside same folder, unless you give it path from main dirrectory like '/' or 'C:\'
You can import a py file with the following statement:
# Other import
import os
import sys
if './dlgo' not in sys.path:
sys.path.insert(0, './dlgo')
from dlgo.gotypes import player
NOTE:
For IDE like PyCharm, you can specify the import path using the Project Structure setting tab (CTRL+ALT+S)
Helpful stack overflow questions [maybe off topic]:
What is the right way to create project structure in pycharm?
Manage import with PyCharm documentation:
https://www.jetbrains.com/help/pycharm/configuring-project-structure.html
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.
I am trying to perform Think Python's turtle-related programs in Eclipse but I always seem to have one error bugging me.
It seems like I have installed Eclipse, Python 2.6 and Python 3.3 correctly in my computer, and linked them to Eclipse via Window>>Preferences>>Interpreter - Python >> New Folder in Libraries. I also did this with Swampy215 and 216.
I run with no problems:
import tkinter
import swampy
from swampy import *
BUT, when I run:
import swampy.TurtleWorld
OR
from swampy import TurtleWorld
I get these error messages:
Traceback (most recent call last):
import swampy.TurtleWorld File "C:\Users\mellofr\Downloads\swampy-2.1.6\swampy\TurtleWorld.py", line 8, in <module>
from Tkinter import TOP, BOTTOM, LEFT, RIGHT, END, LAST, NONE, SUNKEN
ImportError: No module named 'Tkinter'
Weirdly, when I type import swampy. Eclipse suggests "TurtleWorld", but seems to ask for Tkinter (Python 2.7) in this process.
Does changing the first line to
import tkinter as Tkinter
help?
See also:
"ImportError: No module named tkinter" when using Pmw