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.
Related
I am trying to run my python app on my website, and so I've created a virtual environment for all of the packages, and I've correctly installed all of the packages I need. When I check on the file path to my installed packages, they are all pointing to the correct path, and when I got to my site-packages file that they point to, they are all there.
However,
Every time I try to run my app, I get this:
stdin: is not a tty
Traceback (most recent call last):
File "/opt/cpanel/ea-ruby24/root/usr/share/passenger/helper-scripts/wsgi-loader.py", line 369, in <module>
app_module = load_app()
File "/opt/cpanel/ea-ruby24/root/usr/share/passenger/helper-scripts/wsgi-loader.py", line 76, in load_app
return imp.load_source('passenger_wsgi', startup_file)
File "/home/dsmproto/testblockchain/passenger_wsgi.py", line 1, in <module>
import main as application
File "/home/dsmproto/testblockchain/main.py", line 2, in <module>
from wallet import wallet
File "/home/dsmproto/testblockchain/wallet.py", line 1, in <module>
from Cryptodome.PublicKey import RSA
ImportError: No module named Cryptodome.PublicKey
I know that the module is there, but for some reason it is still saying there's no module.
Is there a command I can use in my SSH to check where my app is looking for modules?
All of the modules I have installed are installed correctly. Furthermore, when I open the SSH and run python commands in the terminal, they are able to import all of the modules without any issues.
So how come my app can't find these modules? Is there a way to check to make sure they are looking in the right place?
Thanks in advance for the help
EDIT:
I ran a script in python to look at the sys.path and got this:
/opt/alt/python38/lib64/python38.zip
/opt/alt/python38/lib64/python3.8
/opt/alt/python38/lib64/python3.8/lib-dynload
/home/dsmproto/virtualenv/testblockchain/3.8/lib64/python3.8/site-packages
/home/dsmproto/virtualenv/testblockchain/3.8/lib/python3.8/site-packages
Those are the correct folders that my packages are installed in, yet when I try to run my app, it still says it can't find them.
I am using a docker container with Ubuntu 16.04 Xenial with a Python 3.5.2 virtual environment. Every time I am trying to initialize the server uWSGI I am getting the following Python error:
File "/env/lib/python3.5/site-packages/elasticsearch_dsl/__init__.py", line 5, in <module>
from .search import Search
File "/env/lib/python3.5/site-packages/elasticsearch_dsl/search.py", line 3, in <module>
from elasticsearch.helpers import scan
ImportError: No module named 'elasticsearch.helpers'
I have been running the bash manually inside the docker container to see what is wrong with the module. By running pip list in the virtual environment I can tell that the packages are correctly installed:
# pip list
elasticsearch (2.1.0)
elasticsearch-dsl (0.0.8)
Running sys.path shows that the site packages folder was correctly added to the python path:
import sys
sys.path
[
'',
'/env/lib/python35.zip',
'/env/lib/python3.5',
'/env/lib/python3.5/plat-x86_64-linux-gnu',
'/env/lib/python3.5/lib-dynload',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/env/lib/python3.5/site-packages'
]
There is a __init__.py file within the folder elasticsearch.helpers so that's not the problem. If I try the import from the Python console it will fail as well:
from elasticsearch.helpers import scan
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'elasticsearch.helpers'
But now if I go to the site-packages folder cd /env/lib/python3.5/site-packages and run python console from here, the import will work.
I don't really know why this is happening any help will be appreciated.
ouch... just a rookie mistake. One of the folders of my project was called elasticsearch and that was causing the issue.
Running the following command I found out that my app was simply loading the elasticsearch module from a different location.
import elasticsearch
import pprint, os
pprint.pprint(os.path.abspath(elasticsearch.__file__))
# /var/sites/my_app/elasticsearch/__init__.py
I'm using Tweepy to send some messages to Twitter. I'm getting a long traceback from the API. The traceback settles at:
ImportError: cannot import name Random
I used Pip to install the latest version of Tweepy:
Name: tweepy
Version: 2.3.0
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requires:
When I call
import tweepy
I get this traceback:
Traceback (most recent call last):
File "/Users/dromard/Projects/Drop Playlist/drop.py", line 4, in <module>
import tweepy
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/__init__.py", line 14, in <module>
from tweepy.api import API
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/api.py", line 8, in <module>
from tweepy.binder import bind_api
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/binder.py", line 5, in <module>
import httplib
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 79, in <module>
import mimetools
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
ImportError: cannot import name Random
Process finished with exit code 1
I'm working in PyCharm and confirmed the site package and Python paths are correct in settings. I manually checked in console that the paths are correct, and there are no duplicate locations.
I haven't made any changes to Tweepy. I let Pip install it where it is, as it is. Permissions look correct:
-rw-r--r-- 1 root wheel
If I check Python in console:
- I get the same traceback
- When I run the individual imports, they all execute without error
It all fails out at the random call. I think random is part of Python's core packages, and not part of Tweepy.
I handed this script off to a co-worker, who then used Pip to install tweepy and hit the same traceback. Makes me think Pip might be contributing.
I'm relatively new to Python (programming in general). I looked through other 'import error' articles, but didn't find this specific issue. Any help is appreciated.
I figured this out.
I had created a python file called 'random.py' during the course of experimenting with a random number generating script. My 'import random' call was grabbing this file, which lacked the library Random. It essentially created a conflict with the proper 'random.'
Make sure that you delete the random.py file or overwrite it with another name, then recheck "from random import random".
I could not comment due to low experience.
I also had a xyz.py in a directory and calling a module of same name (import xyz) causes this error.
Make sure you do not save any file xyz.py that also have a python module at the same name.
This is what I found from my newbie experiment.
This also happens with python 3.8.
I installed mod_python, I try to run python script like:
from mod_python import apache
It show me the error message:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
from mod_python import apache
File "D:\Python27\lib\mod_python\apache.py", line 55, in <module>
import _apache
ImportError: No module named _apache
I don't know why?
My enviroment:
Windows XP, Python 2.7.2
If you don't get any help here, try the mod_python mailing list:
http://www.modpython.org/live/mod_python-2.7.8/doc-html/installation.html
Its probably that the script location is not added to your path.
try:
import sys
sys.path
sys.path.append('/path/to/the/mod_python.py')
If this doesn't work, it was probably not installed correctly.
If you want to add it to your system path permanently so you don't have to use the code above every time check out this SO question.
Somehow my python is broken and emits the error:
jseidel#EDP15:/etc/default$ python -c 'import random'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.6/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
This is NOT the virtualenv error that is so commonly documented here and elsewhere: I don't use python directly, I have never setup a virtualenv explicitly, and there is no virtualenv directory or python script that I can find anywhere on my system.
I'm running Kubuntu 10.04 and until just recently my KPackageKit worked just fine and handled updates with no problem. Now it shows nothing... maybe because of this python error, maybe because of something else.
How do I go about finding the error and fixing python?
As suggested by #Armin Rigo, this worked for me:
1) Add a print 42 at the end of the /usr/lib/python2.6/os.py file.
2) If you see "42", then that is the correct os.py file and the urandom module is not include. Add the statement to include urandom (you can find a sample from another os.py file). This was what worked for me.
3) If you don't see "42", then that's not the os.py file that you're using. Find the random.py file that is crashing and insert import os; print os.__file__ to get more information about the failure.