I'm really bad with python. This is on a CentOS7 vm
Problem:
When trying to use awscli in a python virtual environment, I get an error:
(python3ve) [user#ncwv-jlnxnode01 ~]$ aws --version
Traceback (most recent call last):
File "/home/user/venv/python3ve/bin/aws", line 27, in
sys.exit(main())
File "/home/user/venv/python3ve/bin/aws", line 23, in main
return awscli.clidriver.main()
File "/home/user/venv/python3ve/lib64/python3.6/site-packages/awscli/clidriver.py", line 69, in main
driver = create_clidriver()
File "/home/user/venv/python3ve/lib64/python3.6/site-packages/awscli/clidriver.py", line 79, in create_clidriver
event_hooks=session.get_component('event_emitter'))
File "/home/user/venv/python3ve/lib64/python3.6/site-packages/awscli/plugin.py", line 44, in load_plugins
modules = _import_plugins(plugin_mapping)
File "/home/user/venv/python3ve/lib64/python3.6/site-packages/awscli/plugin.py", line 61, in _import_plugins
module = __import__(path, fromlist=[module])
ModuleNotFoundError: No module named '/root/'
ultimately i'm trying to put together a step by step method in an ansible playbook for not only installing awscli, but also awscli-plugin-endpoint, so i'd prefer to install this through pip instead of the centos repos and instead of just downloading the binaries.
Installation Steps:
remove python3 and everything python3 related on the system.
~$ rm -rf ~/venv/python3ve/
~$ sudo yum remove -y python3
~$ sudo yum autoremove -y
~$ sudo find / -name "python3*" > ~/file
~$ sudo xargs rm -r ~/file (missing the arrow because stackoverflow formatting is freaking out with it)
install
~$ sudo yum install -y python3
~$ /usr/bin/python3 -m venv ~/venv/python3ve
~$ source ~/venv/python3ve/bin/activate
~$ ~/venv/python3ve/bin/python3 -m pip install --upgrade pip
~$ ~/venv/python3ve/bin/python3 -m pip install --upgrade awscli
~$ which aws
~/venv/python3ve/bin/aws
~$ aws --version
---output is in the problem description above---
suggestions?
ultimately found that the error was stemming from my ~/.aws/config which I wasnt removing when I reinstalled. that had a reference to the plugin not yet installed and also the old site-packages path (pre venv)
cli_legacy_plugin_path=/root/.local/lib/python3.6/site-packages/
endpoint = awscli_plugin_endpoint
Once I removed those, it worked fine again.
~$ aws --version
aws-cli/1.24.10 Python/3.6.8 Linux/3.10.0-957.el7.x86_64 botocore/1.26.10
The error was referencing /root/ because of how _import_plugins within /awscli/plugin.py splits the path based on . if present
module = path.rsplit('.', 1)
I install python from source:
$ wget -c https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
$ tar xf Python-3.6.1.tar.xz
$ cd Python-3.6.1
$ ./configure --enable-optimizations --prefix=$HOME/.local/ --with-pydebug
$ make altinstall -j8
Then I install pip with get-pip.py
$ python3.6 get-pip.py --prefix=~/.local/
I met the error of:
Traceback (most recent call last): File "get-pip.py", line 27, in
import struct File "/home/zhangzy/.local/lib/python3.6/struct.py", line 13, in
from _struct import * ModuleNotFoundError: No module named '_struct'
What is the cause of this problem and how could it solve it?
You should always use your system package manager when possible. There is a safe way to get newer versions of Python on CentOS/RHEL, as proper RPM packages. It is called the IUS project, and we offer multiple versions of Python.
After setting up the repo, you can get Python 3.5 by running the command yum install python35u. You will then have the command python3.5 available, as well as the pyvenv-3.5 command for creating virtual environments.
at the first I ran this:
pip install -e git://github.com/brokenseal/PyV8-OS-X#egg=pyv8
this message showed :
Obtaining pyv8 from git+git://github.com/brokenseal/PyV8-OS-X#egg=pyv8
Updating ./src/pyv8 clone
Running setup.py egg_info for package pyv8
Installing collected packages: pyv8
Running setup.py develop for pyv8
Checking .pth file support in /usr/local/lib/python2.7/dist-packages/
/usr/bin/python -E -c pass
TEST PASSED: /usr/local/lib/python2.7/dist-packages/ appears to support .pth files
Creating /usr/local/lib/python2.7/dist-packages/PyV8.egg-link (link to .)
PyV8 0.8 is already the active version in easy-install.pth
Installed /root/src/pyv8
Successfully installed pyv8
Cleaning up...
I used this code for run python-Wappalyzer :
from wappalyzer import Wappalyzer
error was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/wappalyzer/__init__.py", line 8, in <module>
from pyv8 import PyV8
File "/root/src/pyv8/pyv8/PyV8.py", line 17, in <module>
import _PyV8
ImportError: /root/src/pyv8/pyv8/_PyV8.so: invalid ELF header
I installed lxml and Requests but not fixed.
how can I fix this problem .I ran this code in ubuntu 14.4 and kali but had same problem.
It seems that you downloaded wrong binary (32 bit, 64 bit) for PyV8
FOR 32 bit arch Use these steps:
$ wget -c "https://raw.githubusercontent.com/emmetio/pyv8-binaries/master/pyv8-linux32.zip"
$ unzip pyv8-linux32.zip
$ sudo cp *PyV8* /usr/lib/python2.7/dist-packages/
For 64 bit arch Use these steps:
$ wget -c "https://raw.githubusercontent.com/emmetio/pyv8-binaries/master/pyv8-linux64.zip"
$ unzip pyv8-linux64.zip
$ rm -rf /usr/lib/python2.7/dist-packages/*PyV8*
$ sudo cp *PyV8* /usr/lib/python2.7/dist-packages/
Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
--------desktop:~$ pip install Django==1.3
Traceback (most recent call last):
File "/home/env/.genv/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
return ep.load()
File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/home/env/.genv/lib/python2.7/site-packages/pip/__init__.py", line 10, in <module>
from pip.util import get_installed_distributions, get_prog
File "/home/env/.genv/lib/python2.7/site-packages/pip/util.py", line 17, in <module>
from pip.vendor.distlib import version
File "/home/env/.genv/lib/python2.7/site-packages/pip/vendor/distlib/version.py", line 13, in <module>
from .compat import string_types
File "/home/env/.genv/lib/python2.7/site-packages/pip/vendor/distlib/compat.py", line 31, in <module>
from urllib2 import (Request, urlopen, URLError, HTTPError,
ImportError: cannot import name HTTPSHandler
I used to edit Modules/setup.dist file and uncomment SSL code lines and rebuilt it, with reference to following thread : http://forums.opensuse.org/english/get-technical-help-here/applications/488962-opensuse-python-openssl-2.html
OSX + homebrew users:
You can get the latest updates to the recipe:
brew reinstall python
But if you still get the issue, e.g. maybe you have upgraded your OS, then you may need to get the latest openssl first. You can check which version and where it is used from:
openssl version -a
which openssl
To get the latest openssl:
brew update
brew install openssl
brew link --overwrite --dry-run openssl # safety first.
brew link openssl --overwrite
This may issue a warning:
bash-4.3$ brew link --overwrite --dry-run openssl
Warning: Refusing to link: openssl Linking keg-only openssl means you may end up linking against the insecure, deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
Side note: this warning means that for other apps, you may want to use
export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
Then recompile python:
brew uninstall python
brew install python --with-brewed-openssl
or for python 3
brew uninstall python3
brew install python3 --with-brewed-openssl
You need to install the OpenSSL header files before building Python if you need SSL support. On Debian and Ubuntu, they are in a package called libssl-dev. You might need some more dependencies, as noted here.
Homebrew
This was probably caused by an upgrade to Mavericks. Here's how I fixed it.
Update OpenSSL
#make a copy of the existing library, just in case
sudo cp /usr/bin/openssl /usr/bin/openssl.apple
# update openssl
brew update
brew install openssl
brew link --force openssl
# reload terminal paths
hash -r
Reinstall Python
Python 3
brew uninstall python3
brew install python3 --with-brewed-openssl
Python 2
brew uninstall python
brew install python --with-brewed-openssl
This answer consolidates all the Stack Exchange answers and comments I found, and is based mostly on this Apple Stack Exchange answer.
I was having this problem on Mac OSX, even after confirming my PATH, etc.
Did a; pip uninstall virtualenv then install virtualenv and it seemed to works now.
At the time I had forced brew to link openssl, unlinked it and virtualenv still seems to work but maybe that's because it was originally linked when I reinstalled it.
You need to install OpenSSl before make and install Python to solve the problem.
On Centos:
yum install openssl openssl-devel -y
source
Another symptom of this problem for me was if I went into the python console of my virtualenv and did import ssl it would error out. Turns out my virtualenv wasn't using the brew version of python, just the default install on my machine. No clue why the default install suddenly stopped working, but here's how I fixed it the problem:
rmvirtualenv myvirtualenv
brew update
brew reinstall python
mkvirtualenv -p /usr/local/Cellar/python/whatever_version_number/bin/python myvirtualenv
It seems your pip requires HTTPSHandler which is part of SSL library.
OSX
On OS X you should link OpenSSL during Python installation (See: #14497).
For Python 2:
brew reinstall python --with-brewed-openssl
pip install --upgrade pip
For Python 3:
brew reinstall python3 --with-brewed-openssl
pip3 install --upgrade pip
You could have multiple Python instances together, to list them run:
brew list | grep ^python
Or list your version via ls -al /usr/local/lib/python*.
I'm using Redhat and have met the same problem.
My solution is :
install openssl and openssl-devel ---- yum install openssl openssl-devel -y
install krb5-devel ---- yum install krb5-devel
change to your python's directory and recompile it ---- make
If I didn't do the 2nd step, when I recompiled my python2.7 , the log would say " fail to build module _ssl".
In many cases this is caused by an out of date virtualenv, here's a script to regenerate your virtualenv(s): https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8
Simply copy it to a file (downloadable link above) and execute it like this: zsh -e recreate_virtualenvs.sh <project_name>
#!/bin/zsh -e
if [ ! -d "$PROJECT_HOME" ]; then
echo 'Your $PROJECT_HOME needs to be defined'
echo 'http://virtualenvwrapper.readthedocs.org/en/latest/install.html#location-of-project-directories'
exit 1
fi
if [ "" = "$1" ]; then
echo "Usage: $0 <project_name>"
exit 1
fi
env="$1"
project_dir="$PROJECT_HOME/$1"
env_dir="$HOME/envs/$1"
function command_exists(){
type $1 2>/dev/null | grep -vq ' not found'
}
if command_exists workon; then
echo 'Getting virtualenvwrapper from environment'
# Workon exists, nothing to do :)
elif [ -x ~/bin/mount_workon ]; then
echo 'Using mount workon'
# Optional support for packaged project directories and virtualenvs using
# https://github.com/WoLpH/dotfiles/blob/master/bin/mount_workon
. ~/bin/mount_workon
mount_file "$project_dir"
mount_file "$env_dir"
elif command_exists virtualenvwrapper.sh; then
echo 'Using virtualenvwrapper'
. $(which virtualenvwrapper.sh)
fi
if ! command_exists workon; then
echo 'Virtualenvwrapper not found, please install it'
exit 1
fi
rmvirtualenv $env || true
echo "Recreating $env"
mkvirtualenv $env || true
workon "$env" || true
pip install virtualenv{,wrapper}
cd $project_dir
setvirtualenvproject
if [ -f setup.py ]; then
echo "Installing local package"
pip install -e .
fi
function install_requirements(){
# Installing requirements from given file, if it exists
if [ -f "$1" ]; then
echo "Installing requirements from $1"
pip install -r "$1"
fi
}
install_requirements requirements_test.txt
install_requirements requirements-test.txt
install_requirements requirements.txt
install_requirements test_requirements.txt
install_requirements test-requirements.txt
if [ -d docs ]; then
echo "Found docs, installing sphinx"
pip install sphinx{,-pypi-upload} py
fi
echo "Installing ipython"
pip install ipython
if [ -f tox.ini ]; then
deps=$(python -c "
parser=__import__('ConfigParser').ConfigParser();
parser.read('tox.ini');
print parser.get('testenv', 'deps').strip().replace('{toxinidir}/', '')")
echo "Found deps from tox.ini: $deps"
echo $deps | parallel -v --no-notice pip install {}
fi
if [ -f .travis.yml ]; then
echo "Found deps from travis:"
installs=$(grep 'pip install' .travis.yml | grep -v '\$' | sed -e 's/.*pip install/pip install/' | grep -v 'pip install . --use-mirrors' | sed -e 's/$/;/')
echo $installs
eval $installs
fi
deactivate
On OSX, brew kept refusing to link against its openssl with this error:
15:27 $ brew link --force openssl
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
I finally was able to get it working with:
brew remove openssl
brew uninstall --force openssl
brew install openssl
export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
brew remove python
brew update
brew install python
For Ubuntu
First check wheather install openssl-develop
sudo apt-get install libssl-dev
Try another way to reinstall pip
sudo apt-get install python-setuptools
sudo easy_install pip
use setuptools to install pip rather than install with source code may can solve the problem of dependency.
Just installed ssl pyopenssl
pip install pyopenssl
I am trying to setup mysqlfailover utility on ec2 instance running Ubuntu 12.04. I performed the following steps:
Downloaded mysql-connector-python:
wget http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python_1.0.12-1debian6.0_all.deb -o mysql-connector-python_1.0.12-1debian6.0_all.deb
(Installed using dpkg -i command.)
Download mysql-utilities:
wget http://cdn.mysql.com/Downloads/MySQLGUITools/mysql-utilities_1.3.5-1debian6.0_all.deb -o mysql-utilities_1.3.5-1debian6.0_all.deb
(Installed using dpkg -i command.)
There were some dependencies issues. I ran the following commands:
sudo apt-get install python-pip
easy_install -U distribute
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
pip install mysql-python
Now, when I run the command mysqlfailover, it gives the following error:
Traceback (most recent call last):
File "/usr/bin/mysqlfailover", line 24, in <module>
from mysql.utilities.common.tools import check_python_version
ImportError: No module named mysql.utilities.common.tools
I have been banging my head around quite some time now, but no success. Any help in the matter is highly appreciated. Thanks.
Try env PYTHONPATH=/usr/share/pyshared/ mysqlfailover
Thers is no utilities in mysql modul, you can check this do:
ls /usr/lib/python2.7/dist-packages/mysql
So you should change mysql package:
cp -r /usr/share/pysharedmysql /usr/lib/python2.7/dist-packages/mysql