folks, i got python 3.5.0 installed on a windows 7 machine and used pip3 to install dependencies cryptography, dateutil, lxml and pytz as mentioned on the freeopcua homepage.
thereafter I installed freeopcua using pip3 as well.
when trying to run one of the examples https://github.com/FreeOpcUa/python-opcua/blob/master/examples/client_to_kepware.py I got the error
1 import sys
2 sys.path.insert(0, "..")
3 import logging
4
5 from opcua import Client
6 from opcua import uaprotocol as ua
"Traceback (most recent call last):
File "xxx\Desktop\opcua.py", line 5, in
from opcua import Client
File "xxx\Desktop\opcua.py", line 5, in
from opcua import Client
ImportError: cannot import name 'Client'"
in my directory "xxx\Python35-32\Lib\site-packages" I do see opcua and freeopcua-0.09.3-py3.5.egg-info so it appears to be intalled correctly.
inside opcua package there is a __init__ importing
from opcua.client.client import Client from a folder client that exists on the same level as __init__. that folder has a module client.py and that module is holding class "Client". so to me everything appears fine but I am not very experienced here.
Not sure what is causing this? thanks for help!
above issue did take me quite some time and after being stuck for one evening I decided to ask. However, I eductated myself on packages that morning and appears like sys.path(0..) is the reason. Not 100% sure why it is used but it somehow changes directory. After puting file into my Python directory /Pyton35-32 it is working
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 *
I am trying to launch a script I wrote that is supposed to read data from a firebase db but it throws the following error:
Traceback (most recent call last):
File "myScript.py", line 8, in <module>
from firebase import Firebase
File "/Users/georgeoprea/Library/Python/3.8/lib/python/site-packages/firebase/__init__.py", line 20, in <module>
from Crypto.PublicKey import RSA
ModuleNotFoundError: No module named 'Crypto'
I have tried to install Crypto in the following ways:
pip3 install Crypto
pip3 install pycryptodome
When I run pip3 show Crypto I get the following output:
Name: crypto
Version: 1.4.1
Summary: Simple symmetric GPG file encryption and decryption
Home-page: https://github.com/chrissimpkins/crypto
Author: Christopher Simpkins
Author-email: git.simpkins#gmail.com
License: MIT license
Location: /Users/georgeoprea/Library/Python/3.8/lib/python/site-packages
Requires: Naked, shellescape
Required-by:
This is the list of imports I have in myScript.py:
from bs4 import BeautifulSoup
import time
import smtplib
from datetime import datetime
import json
import random
from email.message import EmailMessage
from firebase import Firebase
OS info: macOS 12.1 running on M1 Pro.
What could I do to have my script recognise the Crypto module?
This might be somewhat related to this question.
/e:
Ok, since you are using this firebase package, I can hopefully help you out.
First of all, it's the package's fault that it isn't running. While it depends on many external packages, it has none of them defined.
This is what I had to do in a clean virtual environment just to be able to do from firebase import Firebase:
pip install sseclient python_jwt gcloud pycryptodome requests-toolbelt
Here is the requirements.txt I ended up with in the clean environment. Notice, that this was only for importing a single class from the package. There still might be other dependencies hidden somewhere, waiting to throw an exception.
I encourage you to give feedback to the developer about this issue. Even better, fix this yourself and open a Pull Request. You might help others with the same issue.
I found a workaround for this. I simply used another module to read from the firebase db. Instead of using firebase I used firebase_admin as mentioned in the firebase documentation. firebase_admin doesn't use Crypto so there's no more problem from this point of view. However I had to change a little bit how I retrieve and write data.
I am working on a project in which you will need to unpack the archive with all the data and everything will work, without installing packages by the user. I came to the creation of a discord bot, but it gives an error, I do not understand what is associated with it.
Traceback (most recent call last):
File "path\Project Folder\bot.py", line 2, in <module>
import modules.discord
File "path\Project Folder\modules\discord\__init__.py", line 25, in <module>
from .client import Client
File "path\Project Folder\modules\discord\client.py", line 33, in <module>
import aiohttp
ModuleNotFoundError: No module named 'aiohttp'
Before that, I downloaded pythonping absolutely as well and there were no errors when importing it.
Downloaded it like this:
pip install --target="path\Project Folder\modules" pythonping
pip install --target="path\Project Folder\modules" discord.py
The folder where it was downloaded looks like this (initially it was empty):
If I change the import of the discord in the same file, and add pythonping, then everything will work without errors.
from modules.pythonping import ping
#import modules.discord
import botinfo
print(botinfo.BotTag)
At the very end, I manually downloaded the discord archive from github and put it in the modules directory, but since there is no aiohttp, ctrl+click did not redirect to it, after which I already downloaded aiohttp pip install --target="path\project folder\modules" aiohttp and ctrl+click began to go to aiohttp, but the error remained (absolutely the same).
Additional information:
python --version Python 3.8.2
pip --version pip 21.0.1
For some reason, the python version decided to change from the last to the previous one, which is why discord did not run on the NEW version, because it still took packages not from the project directory, but from the interpreter directory. I switched to an earlier version of python and it worked, then I forcibly downloaded it to the new version and it also worked.
I think running the following command might be a good idea :
pip install aiohttp
I have a question that I assume has a simple answer, but for some reason I am struggling to find it on my own. I have created and activated a virtual environment with virtualenv, and I am trying to install all the necessary packages in order to create a requirements.txt file.
I have, for example, a Python file that begins like this:
import xml.etree.ElementTree as ET
from lib.project import Projector
from lib import writer
import os
import datetime
from datetime import timedelta
from datetime import datetime
import pprint
When I try to run this file from the virtual machine, I receive the following error:
Traceback (most recent call last):
File "readMap.py", line 2, in <module>
from lib.project import Projector
ModuleNotFoundError: No module named 'lib.project'
My problem is that I'm not sure why the virtual environment can't find project.py. My directory structure is:
regiaoSul
lib
__init__.py
arrival_conversion.py
coord_conversion.py
message_conversion.py
project.py
route_conversion.py
stop_conversion.py
wkt_parser.py
writer.py
readMap.py
json_generator.py
The import on line 2 implies lib is a module rather than "a simple repository".
I will try running the script with the flag -m. Something like this -
python -m script_name
make sure to drop the .py extension when you run with -m flag.
Another advice: you don't need to install python files to the virtual environment, they are not some external libraries. They only need to be present (with the same order of packaging) when you run your script.
Thanks to everyone who responded. I believe the issue was some sort of dependency problem. In readMap.py I had imported writer from lib, and in writer.py I had imported Projector from project. I moved the function that required Projector from writer.py to readMap.py and it worked.
I still don't fully understand why this was a problem. Until recently I had been running my scripts in PyCharm and they all worked with the structure I had. It was only when I tried to run them from the command line in my virtual machine that they didn't work.
If anybody would like to explain the distinction to me and what the exact problem was with my imports, feel free to.
I sometimes face the same issue. A solution is to add the path to sys.path by:
import sys
sys.path.insert(0, "/path/to/your/package_or_module")
Working on code that SSH's into terminal on an external device. This morning the code was able to do so. Then I updated Windows because I had put it off for a while. This was the only thing I did that I could think of may have had an effect.
I now run into a ModuleNotFoundError.
I tried updating pip, uninstalling and reinstalling ssh2-python. I changed python37 folder to read/write. Tried locating the module in python37/Lib/site-packages but not really sure what I'm looking for
SSH's into address' terminal
import socket
from ssh2.session import Session
Expected:
input for ip address
Result:
Traceback (most recent call last):
File "C:/Users/louis/Desktop/ssh2.py", line 4, in <module>
from ssh2.session import Session
File "C:\Users\louis\Desktop\ssh2.py", line 4, in <module>
from ssh2.session import Session
ModuleNotFoundError: No module named 'ssh2.session'; 'ssh2' is not a package
I had named a file in the same directory ssh2. Python loaded that instead of the module. Simply renamed the file to anything else and python was able to find the ssh2 module.