im running "import requests" as non root user and its giving me this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 108, in <module>
from .__version__ import __title__, __description__, __url__, __version__
ImportError: No module named __version__
but i dont get that error when i try to import it as root. I'm assuming its a permission issue and I changed the permissions on
/lib/python2.7/site-packages/version-0.1.1-py2.7.egg-info/
and also on /lib/python2.7/site-packages/version.py
but that didnt solve my problems. any ideas?
You don't have problems with /lib/python2.7/site-packages/version.py, you have a problem with /usr/lib/python2.7/site-packages/requests/__version__.py. Try to fix permissions on the file:
sudo chmod a+r /usr/lib/python2.7/site-packages/requests/__version__.py
or the entire package:
sudo chmod -R a+rX /usr/lib/python2.7/site-packages/requests
or may be the entire site-packages directory:
sudo chmod -R a+rX /usr/lib/python2.7/site-packages
And next time you do sudo pip install verify that your root umask is 022:
sudo bash -c umask
If it's not either change it in /root/.bashrc or run pip install with the proper umask:
sudo bash -c "umask 022; pip install…"
Related
I have installed elastalert on Centos 7.6 and while starting the elastalert receiving the following error.
[root#e2e-27-36 elastalert]# python -m elastalert.elastalert --verbose --rule example_rules/example_frequency.yaml
Traceback (most recent call last):
File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/root/elastalert/elastalert/elastalert.py", line 29, in <module>
from . import kibana
File "elastalert/kibana.py", line 4, in <module>
import urllib.error
ImportError: No module named error
How should I go about fixing this?
You can try to check if urllib3 is installed by running pip freeze or try to reinstall it with pip install urllib3.
You maybe need to correctly activate your environment variable like this : source [env]/bin/activate.
Setup conda environment
conda create -n elastalert python=3.6 anaconda
Activate conda env
conda activate elastalert
Install all the requirements
pip install -r requirements-dev.txt
pip install -r requirements.txt
I have found my fix by own.
1.On python2.7 the issue still persist
2.Install python3.6 version to fix the issue.
yum install python3 python3-devel python3-urllib3
3.Run the elastalert command
python3 -m elastalert.elastalert --config /root/elastalert/config.yaml --verbose --rule /root/elastalert/example_rules/example_frequency.yaml
4.If you received issue with the modules (ModuleNotFoundError: No module named 'pytz')
5.Install the modules as per the requirement.
pip3 install -r /root/elastalert/requirements.txt
6.Let's run the command "python3 -m elastalert.elastalert --config /root/elastalert/config.yaml --verbose --rule /root/elastalert/example_rules/example_frequency.yaml" and got error
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='elasticsearch.example.com', port=9200): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',))
7.Above error due to not valid hostname on config.yaml file. Edit the config.yaml file and change the hostname to server hostname at es.hosts field
Make sure you had an entry for the same on the /etc/hosts file.
8.Ok the issue got fixed and run the command "python3 -m elastalert.elastalert --config /root/elastalert/config.yaml --verbose --rule /root/elastalert/example_rules/example_frequency.yaml" and one more error
pkg_resources.DistributionNotFound: The 'jira>=2.0.0'
9.We need to install the jira by using below command
pip3 install jira==2.0.0
10.Now let's run the command "python3 -m elastalert.elastalert --config /root/elastalert/config.yaml --verbose --rule /root/elastalert/example_rules/example_frequency.yaml" and again another error OMG.
elasticsearch.exceptions.TransportError: TransportError(429, 'circuit_breaking_exception', '[parent] Data too large, data for [] would be [994793504/948.7mb], which is larger than the limit of [986061209/940.3mb], real usage: [994793056/948.7mb], new bytes reserved: [448/448b]')
11.You need to fix the same by changing the heap value on following /etc/elasticsearch/jvm.options
Xms-1g to Xms-2g
Xmx-1g to Xms-2g
and restart elasticsearch service "service elasticsearch restart"
12.Everything set again run the command "python3 -m elastalert.elastalert --config /root/elastalert/config.yaml --verbose --rule /root/elastalert/example_rules/example_frequency.yaml" and ended up receiving another error.
ERROR:root:Error finding recent pending alerts: NotFoundError(404, 'index_not_found_exception', 'no such index [elastalert_status]', elastalert_status, index_or_alias) {'query': {'bool': {'must': {'query_string': {'query': '!exists:aggregate_id AND alert_sent:false'}}, 'filter': {'range': {'alert_time': {'from': '2019-12-04T19:45:09.635478Z', 'to': '2019-12-06T19:45:09.635529Z'}}}}}, 'sort': {'alert_time': {'order': 'asc'}}}
13.Fix the issue by running the below command
elastalert-create-index
14.Finally everything done and run the below command
python3 -m elastalert.elastalert --config /root/elastalert/config.yaml --verbose --rule /root/elastalert/example_rules/example_frequency.yaml
Now cancelled the command and ran the same on background
python3 -m elastalert.elastalert --config /root/elastalert/config.yaml --verbose --rule /root/elastalert/example_rules/example_frequency.yaml &
A few days ago I wanted to run dnf but I received the following error
Traceback (most recent call last):
File "/usr/bin/dnf", line 57, in <module>
from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'
Thus I tried to run yum and I received something similar:
Traceback (most recent call last):
File "/usr/bin/yum", line 57, in <module>
from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'
I do not know what happened and I hope someone can help me find the problem and solve it. The only thing I know is that it might be related to the fact that a few days before I installed tensorflow in python using conda. Although it seems conda does not work now because I get this:
Traceback (most recent call last):
File "/usr/bin/conda", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3126, in <module>
#_call_aside
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3110, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3139, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 581, in _build_master
ws.require(__requires__)
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 898, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 784, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'conda==4.5.11' distribution was not found and is required by the application
I am using fedora 29
Thanks!
I had the same problem, but after all trial and error the only thing actually worked was:
rpm -qa python3
This will announce your python3 rpm package.
I've searched and downloaded it from web
Go to the downloaded directory like:
sudo rpm -e --nodeps python3-3.7.2-4.fc29.x86_64(my python3 rpm package)
sudo rpm -i python3-3.7.2-4.fc29.x86_64.rpm
I tried many other methods so this'll not be a only factor that resolve that problem.
Hello,
i have just been through this in Fedora 31 and do not exactly know what was the cause that led to this same issue, it must have been some package managing over another context that came up only on my next need to use DNF.
I am assuming that before this stated error:
Traceback (most recent call last):
File "/usr/bin/dnf", line 57, in
from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'
You were having this message when executing dnf:
/usr/local/lib/python3.7/site-packages/dnf.py:15: UserWarning: The DNF Python API is not currently available via PyPI.
Please install it with your distro package manager (typically called
'python2-dnf' or 'python3-dnf'), and ensure that any virtual environments
needing the API are configured to be able to see the system site packages
directory.
After some hours researching and trying to install each DNF rpm dependency of the DNF rpm itself(https://pkgs.org/download/dnf) i felt as an intuition that maybe i should try to remove(mv sure)
/usr/local/lib/python3.7/
which had just one folder in it named site-packages
It worked!
Thank you.
I have a friend who met the same problem.
He tried to uninstall python3.7 in linux server by some amazing cmd rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps and whereis python3 |xargs rm -frv.
This caused the yum and dnf to break.
I changed the /usr/bin/yum to use a local python3.8 version, but it caused ModuleNotFoundError: No module named 'dnf' at last, and didn't solved it.
It is not a good way to download many rpm packages on the Internet. And I can't use yum either. But I have another same linux OS server, so I've tried to copy the correlation files about python3.7.
$ rpm -ql python3-3.7.0-9.h4.eulerosv2r8.aarch64> py.log
$ while read -r line;do dirname $line |xargs -I {} ssh root#$remoteip "mkdir -p {}" ;scp $line root#$remoteip:$line ;done<py.log
$ rpm -ql python3-libs-3.7.0-9.h4.eulerosv2r8.aarch64 >pylib.log
$ while read -r line;do dirname $line |xargs -I {} ssh root#$remoteip "mkdir -p {}" ;scp $line root#$remoteip:$line ;done<pylib.log
scp -r /usr/lib/python3.7/site-packages root#$remoteip:/usr/lib/python3.7/
I recovered yum this way.
I had the same issue.
For me the solution was to simply uninstall the python3 dnf package (including from all virtualenvs) that I had obviously installed somewhen.
pip uninstall dnf
had the same error.
my fix ->
cd into /usr/bin. has many python files...
latest python (3.11) has pytest, python3 -> python3.11 (symlink), python3.11, python3.11-config, python3.11-x86_64-config, python -> python3
had been using 3.9, not familiar with python so much, so changed symlink back to python3->python3.9 after Fedora 36 update changed symlink to 3.11 and installed python3.11. when i changed symlink back to 3.9, this created the error message. When i changed the symlink back to python3->python3.11 the error disappeared and all works fine. DNF is fine etc. did nothing else.
since all the other python files were pointing to the 3.11 versions, introduction of the symlink to 3.9 must have blown the fuse...
Hey after making some changes in the bashrc I tried to use
source ~/.bashrc
but got the following error
baaz#FireStorm:~$ source ~/.bashrc
Traceback (most recent call last):
File "/usr/lib/python3.5/dbm/gnu.py", line 4, in <module>
from _gdbm import *
ImportError: No module named '_gdbm'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 7, in <module>
import dbm.gnu as gdbm
File "/usr/lib/python3.5/dbm/gnu.py", line 6, in <module>
raise ImportError(str(msg) + ', please install the python3-gdbm package')
ImportError: No module named '_gdbm', please install the python3-gdbm package
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 27, in <module>
from CommandNotFound.util import crash_guard
File "/usr/lib/python3/dist-packages/CommandNotFound/__init__.py", line 3, in <module>
from CommandNotFound.CommandNotFound import CommandNotFound
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 9, in <module>
import gdbm
ImportError: No module named 'gdbm'
I tried using the install commands as mentioned in the error
baaz#FireStorm:~$ sudo apt-get install python3-gdbm
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-gdbm is already the newest version (3.6.5-3~16.04.york0.2).
python3-gdbm set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Also some solutions mentioned to use version specific commands, but still got no solution
baaz#FireStorm:~$ sudo apt-get install python3.5-gdbm
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package python3.5-gdbm is a virtual package provided by:
python3-gdbm 3.5.1-1 [Not candidate version]
E: Package 'python3.5-gdbm' has no installation candidate
The pip install command gave the following error
baaz#FireStorm:~$ sudo pip3 install gdbm --upgrade
The directory '/home/baaz/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/baaz/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting gdbm
Could not find a version that satisfies the requirement gdbm (from versions: )
No matching distribution found for gdbm
Please suggest a way to sort out these error.
Your error is occurring most likely because your .bashrc contains a typo somewhere, therefore command-not-found is being called, but command-not-found appears to have been recently broken. (You should get the same error if you type some nonsense into your terminal directly.)
sudo apt install python3-gdbm=3.5.1-1
worked for me.
From running
dpkg -L python3-gdbm
it looked like gdbm on my computer is being installed to python3.6 for some reason, not python3.5, but my python3 version is python3.5 (and last I checked python3.6 breaks something on ubuntu 16.04).
The error you got when you ran
sudo apt-get install python3.5-gdbm
complained about a version issue, hence manually installing the version they noted worked.
This worked for me:
sudo ln -s /usr/lib/python3.6/lib-dynload/_gdbm.cpython-36m-x86_64-linux-gnu.so /usr/lib/python3.5/lib-dynload/_gdbm.cpython-35m-x86_64-linux-gnu.so
Note the 35m in the the link's name.
I'm working on Linux Mint 17 and I'm trying to create a new virtualenv with Python3 like this:
python3.6 -m venv env
And this is the error that I get:
Error: Command '['/home/ric/myprojs/django-example-channels/env/bin/python3.6', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
I've googled this error message but haven't managed to find anything too informative.
This is my pip version, in case it make any difference:
pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
I've been using Python2 for some time, but I'm new to Python3. I don't know what I may be missing.
UPDATE 1:
Answering #cezar's question, when I type which python3 this is what I get:
$ which python3
/usr/bin/python3
UPDATE 2:
Answering #Chłop Z Lasu:
$ virtualenv -p python3.6 env
Running virtualenv with interpreter /usr/bin/python3.6
Using base prefix '/usr'
New python executable in /home/ric/myprojs/django-example-channels/example_channels/env/bin/python3.6
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 2328, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 713, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 925, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 1231, in install_python
shutil.copyfile(executable, py_executable)
File "/usr/lib/python3.6/shutil.py", line 104, in copyfile
raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
The error indicates that virtualenv is trying to make an environment in your python path. therefore, you have to specify your virtualenv destination
virtualenv -p python3.6 /path/to/yourenv
For venv and python3.6 installing venv one can use below to fix the issue
sudo apt install python3.6-venv
You gotta install the venv via code bellow:
sudo apt install python3.6-venv
Expanding on the Answer Above:
The error indicates that virtualenv is trying to make an environment in your python path. therefore, you have to specify your virtualenv destination
Since -p is a flag equivalent to --python, you can also use.
$ virtualenv --python=python3.6 /path/to/yourenv
Or
$ virtualenv -p python3.6 /path/to/yourenv
i am using redhat 5.3
I using following command to update python to 2.7. (it was python 2.4 before update)
# xz -d Python-2.7.6.tar.xz
# tar xvf Python-2.7.6.tar
# cd Python-2.7.6/
# ./configure
# make && make install
And I Install the python-setuptools
# yum install python-setuptools
Then I install the pip print the error
^
SyntaxError: invalid syntax
File "/usr/lib/python2.4/site-packages/pip-1.5.6-py2.4.egg/pip/_vendor/colorama/__init__.py", line 2
from .initialise import init, deinit, reinit
^
SyntaxError: invalid syntax
File "/usr/lib/python2.4/site-packages/pip-1.5.6-py2.4.egg/pip/_vendor/colorama/winterm.py", line 2
from . import win32
^
SyntaxError: invalid syntax
Adding pip 1.5.6 to easy-install.pth file
Installing pip script to /usr/bin
Installing pip2 script to /usr/bin
Installing pip2.4 script to /usr/bin
Installed /usr/lib/python2.4/site-packages/pip-1.5.6-py2.4.egg
Processing dependencies for pip
And I run the command pip , it print following errors:
# pip
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2603, in <module>
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 666, in require
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: pip==1.5.6
And I try to uninstall that, it tell me that:
[root#linkea-dev-srv1 /]# yum remove pip
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Setting up Remove Process
No Match for argument: pip
Loading mirror speeds from cached hostfile
No Packages marked for removal
You have new mail in /var/spool/mail/root
So I try to reinstall pip by python get-pip.py.
It also has error.
# python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 17474, in <module>
main()
File "get-pip.py", line 17466, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 17406, in bootstrap
import pip
File "/tmp/tmpB9jhvw/pip.zip/pip/__init__.py", line 9, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/log.py", line 9, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/__init__.py", line 2, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/initialise.py", line 5, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/ansitowin32.py", line 6, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/winterm.py", line 2, in <module>
File "/tmp/tmpB9jhvw/pip.zip/pip/_vendor/colorama/win32.py", line 7, in <module>
File "/usr/local/lib/python2.7/ctypes/__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
You should be very careful when upgrading Python on RedHat (including Fedora/CentOS) because a large majority of the system applications rely on the bundled version of Python. This is especially true of yum, which relies on the version of Python that comes bundled with the operating system.
In short - if you upgrade the version of Python on RedHat/CentOS/Fedora, yum will not work correctly.
To install a different version of Python on these distributions, you have two main options. One is to find someone that has released a rpm, download an install that; but you may have to deal with dependencies on your own.
The other (simpler) option is to download the source of Python, compile it and then install it separately (using altinstall).
You'll need to install the following packages first:
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel
Next, download the source and extract it. As of this writing, the latest version is 2.7.8:
wget "https://www.python.org/ftp/python/2.7.8/Python-2.7.8.xz"
tar xvf Python-2.7.8.xz
cd Python-2.7.8
Now you have to build and install Python to an alternate location, with the following:
./configure --prefix=/usr/local
make && make altinstall
Once this is done, you'll have /usr/local/bin/python2.7 available to you. Next, you'll want to install pip for this version of Python. To do that, first install setuptools:
wget "https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py"
/usr/local/bin/python2.7 ez_setup.py
/usr/local/bin/easy_install-2.7 pip
The final step is to make sure that this version of Python is available to you. You can add /usr/local/bin/ to your $PATH by modifying your shell's environment (for example, adding it in $HOME/.bashrc); or you can as root create symbolic links in /usr/bin/ to these utilities. Make sure you give them version-specific tags:
ln -sf /usr/local/bin/python2.7 /usr/bin/python2.7
ln -sf /usr/local/bin/pip /usr/local/bin/pip2.7
This will keep your default Python to the system's version (recommended), and then give you the option to use 2.7 when needed.