virtualenvwrapper no longer installs - virtualenv

I build a development environment using vagrant and virtualenv/virtualenvwrapper. Recently, my vagrant box stopped provisioning correctly. It seems virtualenvwrapper won't install anymore. I am trying to trace down what has changed. What has changed?
My Vagrantfile and install.sh files are here: https://gist.github.com/ErikEvenson/9763878. Note that this error happens on the web box.
This is the error I get when I try to install virtualenvwrapper:
vagrant#vagrant-ubuntu-precise-64:~$ pip install virtualenvwrapper
Downloading/unpacking virtualenvwrapper
Downloading virtualenvwrapper-4.2.tar.gz (125Kb): 125Kb downloaded
Running setup.py egg_info for package virtualenvwrapper
Installed /home/vagrant/build/virtualenvwrapper/pbr-0.7.0-py2.7.egg
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/vagrant/build/virtualenvwrapper/setup.py", line 7, in <module>
pbr=True,
File "/usr/lib/python2.7/distutils/core.py", line 112, in setup
_setup_distribution = dist = klass(attrs)
File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 221, in __init__
self.fetch_build_eggs(attrs.pop('setup_requires'))
File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 245, in fetch_build_eggs
parse_requirements(requires), installer=self.fetch_build_egg
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 588, in resolve
raise VersionConflict(dist,req) # XXX put more info here
pkg_resources.VersionConflict: (pip 1.0 (/usr/lib/python2.7/dist-packages), Requirement.parse('pip>=1.4'))
Complete output from command python setup.py egg_info:
Installed /home/vagrant/build/virtualenvwrapper/pbr-0.7.0-py2.7.egg
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/home/vagrant/build/virtualenvwrapper/setup.py", line 7, in <module>
pbr=True,
File "/usr/lib/python2.7/distutils/core.py", line 112, in setup
_setup_distribution = dist = klass(attrs)
File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 221, in __init__
self.fetch_build_eggs(attrs.pop('setup_requires'))
File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 245, in fetch_build_eggs
parse_requirements(requires), installer=self.fetch_build_egg
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 588, in resolve
raise VersionConflict(dist,req) # XXX put more info here
pkg_resources.VersionConflict: (pip 1.0 (/usr/lib/python2.7/dist-packages), Requirement.parse('pip>=1.4'))
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/vagrant/.pip/pip.log

Erik, while your answer may work it's not necessary I don't think. Have you tried apt-get install virtualenvwrapper?
The reason I ask is that ubuntu already has you "sudo apt-get install python-virtualenv" (which also installs python-pip), and I had no problem also apt-get install'ing virtualenvwrapper. The only difference is you have to "source /etc/bash_completion.d/virtualenvwrapper" in your bashrc instead of /usr/local/bin/virtualenvwrapper.sh.
You can still try back your way out of what you've done (don't blame me if it doesn't work though!):
$ sudo apt-get uninstall python-pip
$ sudo apt-get install python-pip
$ sudo pip uninstall virtualenvwrapper
$ sudo apt-get install virtualenvwrapper
then add source /etc/bash_completion.d/virtualenvwrapper to ~/.bashrc
Something like that. Good luck!

Running pip install --upgrade pip after doing apt-get install python-pip seems to have done the trick. This bring pip up to 1.5.4 and avoids the error above. Also, be sure to use /user/local/bin/pip for the rest of the provisioning script.
I'm not sure what changed to make my provisioning dependent on pip > 1.0 though. Would be nice to know so that I can lock that dependency down.

You can try
sudo apt-get install python-virtualenv virtualenwrapper.

Related

Installing Cryptography on an Apple Silicon M1 Mac

Help! I'm trying to install cryptography on my m1. I know I can run terminal in rosetta mode, but I'm wondering if there is a way not to do that.
Output:
ERROR: Command errored out with exit status 1:
command: /opt/homebrew/opt/python#3.9/bin/python3.9 /opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/tmpl4sga84k
cwd: /private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-install-jko4b562/cryptography_7b1bbc9ece2f481a8e8e9ea03b1a0030
Complete output (55 lines):
=============================DEBUG ASSISTANCE=============================
If you are seeing a compilation error please try the following steps to
successfully install cryptography:
1) Upgrade to the latest pip and try again. This will fix errors for most
users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
2) Read https://cryptography.io/en/latest/installation.html for specific
instructions for your platform.
3) Check our frequently asked questions for more information:
https://cryptography.io/en/latest/faq.html
=============================DEBUG ASSISTANCE=============================
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
main()
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 133, in prepare_metadata_for_build_wheel
return hook(metadata_directory, config_settings)
File "/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 161, in prepare_metadata_for_build_wheel
self.run_setup()
File "/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 145, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 44, in <module>
setup(
File "/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/opt/homebrew/Cellar/python#3.9/3.9.1_7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 432, in __init__
_Distribution.__init__(self, {
File "/opt/homebrew/Cellar/python#3.9/3.9.1_7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 292, in __init__
self.finalize_options()
File "/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 708, in finalize_options
ep(self)
File "/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 715, in _finalize_setup_keywords
ep.load()(self, ep.name, value)
File "/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/cffi/setuptools_ext.py", line 219, in cffi_modules
add_cffi_module(dist, cffi_module)
File "/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/cffi/setuptools_ext.py", line 49, in add_cffi_module
execfile(build_file_name, mod_vars)
File "/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/cffi/setuptools_ext.py", line 25, in execfile
exec(code, glob, glob)
File "src/_cffi_src/build_openssl.py", line 77, in <module>
ffi = build_ffi_for_binding(
File "src/_cffi_src/utils.py", line 54, in build_ffi_for_binding
ffi = build_ffi(
File "src/_cffi_src/utils.py", line 74, in build_ffi
ffi = FFI()
File "/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/cffi/api.py", line 48, in __init__
import _cffi_backend as backend
ImportError: dlopen(/private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so, 2): Symbol not found: _ffi_prep_closure
Referenced from: /private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so
Expected in: flat namespace
in /private/var/folders/hj/5zfkv68d7lqgrfqt046bn23c0000gn/T/pip-build-env-9bqzge_f/overlay/lib/python3.9/site-packages/_cffi_backend.cpython-39-darwin.so
I've tried to build and run like their instructions say in that code block to the same error. I've looked around and nobody has seemingly found the fix yet, but those things are two months old usually. What am I missing?
This issue is due to a mismatch between the libffi header version and the version of libffi the dynamic linker finds. In general it appears users encountering this problem have homebrew libffi installed and have a Python built against that in some fashion.
When this happens cffi (a cryptography dependency) compiles, but fails at runtime raising this error. This should be fixable by passing the right path as a linker argument. To reinstall cffi you should pip uninstall cffi followed by
LDFLAGS=-L$(brew --prefix libffi)/lib CFLAGS=-I$(brew --prefix libffi)/include pip install cffi --no-binary :all:
This is an ugly workaround, but will get you past this hurdle for now.
Update: I've uploaded arm64 wheels for macOS so the below compilation is no longer required if your pip is up-to-date. However, if, for some reason you wish to compile it yourself:
LDFLAGS="-L$(brew --prefix openssl#1.1)/lib" CFLAGS="-I$(brew --prefix openssl#1.1)/include" pip install cryptography
I'm using Macbook Pro M1 2020 model and faced the same issue. The issue was only with my cffi and pip versions maybe. Because these 4 steps helped me -
Uninstalling old cffi pip uninstall cffi
Upgrading pip python -m pip install --upgrade pip
Reinstalling cffi pip install cffi
Intalling cryptography pip install cryptography
Probably, you'll have a problem with more packages and each has it's own solution for Apple Silicon, it's exhausting.
I came to final solution: using x86_x64 Homebrew which installs x86 packages, including Python. Thus, all your requirements are installing as on the x86_x64 macs and there are no more problems with the compilation errors and so on.
Instructions:
Run iTerm2 (or default Terminal app) under Rosetta 2 (right click on the app icon -> Get info -> Open using rosetta).
Install homebrew as usual /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" or you can get this link from https://brew.sh/ for security reasons (never copy curl commands from stackoverflow without double-checking).
Add an alias in your ~/.zshrc (if you're using ZSH) or ~/.bash_profile (if you're bash user): alias brew='arch -x86_64 /usr/local/bin/brew'.
Turn off Open using rosetta in iTerm2 Get info.
Now, every time you'll print brew in terminal apps you'll run x86_x64 Homebrew. And when you install any package from brew, it'll work under Rosetta 2 automatically.
A little late to the party, but the solutions above didn't work for me. Paul got me on the right track, but my problem was that pyenv used the mac libffi for its build and cffi used the homebrew version. I read this somewhere, can't claim this unique insight.
My solution was to ensure that my python (3.8.13) was built by pyenv using the homebrew libffi by ensuring correct headers libraries and package config:
export LDFLAGS="-L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib -L$(brew --prefix openssl#1.1)/lib -L$(brew --prefix libffi)/lib"
export CPPFLAGS="-I$(brew --prefix zlib)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix openssl#1.1)/include -I$(brew --prefix libffi)/include"
export PKG_CONFIG_PATH="$(brew --prefix openssl#1.1)/lib/pkgconfig:$(brew --prefix libffi)/lib/pkgconfig"
rebuilding python...
pyenv uninstall 3.8.13
pyenv install 3.8.13
killing the pip cache
pip cache purge
and, finally, reinstalling my dependencies using pipenv
pipenv --rm
pipenv sync --dev
After these steps, I was free from the dreaded
ImportError: dlopen(/private/var/folders/k7/z3mq67_532bdr_rcm2grml240000gn/T/pip-build-env-apk5b25z/overlay/lib/python3.8/site-packages/_cffi_backend.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_ffi_prep_closure'
This answer here worked like a charm! #paveldroo
As an extension to the answer above, I went ahead and saved the alias in step 3 as alias ibrew='arch -x86_64 /usr/local/bin/brew' at ~/.zshrc
This means when I install anything with brew command, it gets installed for M1 architecture, and when I install with ibrew command it gets installed for -x86_64 architecture.
As a consequence, I installed two instances of python3 at my system one at /opt/homebrew/bin/python3 using brew and the other at /usr/local/bin/python3 using ibrew
The two versions adds some flexibility on creating the project virtual environments as needed. For example you could create virtual environments using:
/usr/local/bin/python3 -m venv venv for -x86_64 architecture
/opt/homebrew/bin/python3 -m venv venv for M1 architecture
I wasn't able to previously install cffi, until I discovered an unrelated issue. I was at this for about two days, until I found this command:
python3 -m ensurepip --upgrade
Magically, everything started working for me. It came from an issue between Python and Pip coming from different sources.
Answer stolen from this question: using pip3: module "importlib._bootstrap" has no attribute "SourceFileLoader"
Edit: This may be a courtesy of the above poster, so could be unrelated. If so, thank you anonymous human!
I have uninstalled older version of cffi and cryptography,
pip uninstall cffi
pip uninstall cryptography
and updated the requirements.txt file from exact versions to updated versions
# requirements.txt
cffi>=1.15.1
cryptography>=38.0.1
(version number can be different).
This resolved my issue

How can I import libraries in PythonAnywhere and use them in a Python notebook?

I'm both updating and installing packages/libaries, but are only able to use them through the Python3.6 console.
10:40 ~ $ pip3.6 install -U --user scikit-learn
Requirement already up-to-date: scikit-learn in ./.local/lib/python3.6/site-packages
Requirement already up-to-date: numpy>=1.11.0 in ./.local/lib/python3.6/site-packages (from scikit-learn)
Requirement already up-to-date: joblib>=0.11 in ./.local/lib/python3.6/site-packages (from scikit-learn)
Requirement already up-to-date: scipy>=0.17.0 in ./.local/lib/python3.6/site-packages (from scikit-learn)
When using pip install it fails with :
10:40 ~ $ pip install -U --user scikit-learn
Collecting scikit-learn
Using cached https://files.pythonhosted.org/packages/18/28/5a48b00599b476875415b97bdfdb3849bafb31183c1d785501dbc8a77aa2/scikit-learn-0.22.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-JYw8w1/scikit-learn/setup.py", line 47, in <module>
import sklearn
File "sklearn/__init__.py", line 81, in <module>
from . import __check_build # noqa: F401
File "sklearn/__check_build/__init__.py", line 46, in <module>
raise_build_error(e)
File "sklearn/__check_build/__init__.py", line 41, in raise_build_error
%s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: No module named _check_build
___________________________________________________________________________
Contents of sklearn/__check_build:
__init__.py _check_build.pyx __init__.pyc
setup.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
It appears that you are importing a local scikit-learn source tree. For
this, you need to have an inplace install. Maybe you are in the source
directory and you need to try from another location.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-JYw8w1/scikit-learn/
If you've installed a package using pip3.6, make sure that your kernel version for your notebook is 3.6 -- if it's (say) 3.7, then it won't work, because each version of Python has its own separate set of installed modules.
I imported the notebook, and forgot to change Kernel Python3.6. It was still on Python3. Changed notebook to 3.6, and the it used the updated libary's-
When you run pip on PythonAnywhere, outside virtual environment, it installs packages for python2. The latest version of scikit-learn to work with python2 is 0.20.4. So, install it with pip install scikit-learn==0.20.4
You tried to install 0.22.1 with python2.

How can I fix an import error in kali Linux?

While Installing Man in the Middle Framework (MITMf) i get an ImportError:No Module named capstone..
Although Capstone is already installed in my Kali Machine
I downloaded MITMf from https://github.com/byt3bl33d3r/MITMf
Heres what i get
root#kali:~/Desktop/MITMf# python mitmf.py --help
Traceback (most recent call last):
File "mitmf.py", line 36, in <module>
from plugins import *
File "/root/Desktop/MITMf/plugins/filepwn.py", line 72, in <module>
from libs.bdfactory import pebin
File "/root/Desktop/MITMf/libs/bdfactory/pebin.py", line 49, in <module>
from intel.intelCore import intelCore
File "/root/Desktop/MITMf/libs/bdfactory/intel/intelCore.py", line 38, in <module>
from capstone import *
ImportError: No module named capstone
root#kali:~/Desktop/MITMf# pip install capstone
Requirement already satisfied: capstone in /usr/lib/python3/dist-packages (3.0.5)
root#kali:~/Desktop/MITMf#
You need to install the python2.7 version of capstone. It looks like your python installation is a little weird. On Debian systems such as Kali, pip should be the installer for python2 packages and pip3 should be the installer for python3 packages.
From the pip man page:
On Debian, pip is the command to use when installing packages for Python 2, while pip3 is the command to use when installing packages for Python 3.
You probably should fix your pip installation by linking pip2 to pip. The way we do this is removing the pip binary and creating a symlink from pip2:
[k#box]$ sudo rm /usr/bin/pip
[k#box]$ sudo ln -s /usr/bin/pip2 /usr/bin/pip
Then you should be able to install the python2.7 version with pip
[k#box]$ pip install capstone
Explanation:
You have installed the python3.6 version of capstone. You can see in the output of your pip install command:
root#kali:~/Desktop/MITMf# pip install capstone
Requirement already satisfied: capstone in /usr/lib/python3/dist-packages (3.0.5)
If you look at the script mitmf.py, you will notice that the top line specifies python2.7
[k#box]$ head -n3 mitmf.py
#!/usr/bin/env python2.7
# Copyright (c) 2014-2016 Moxie Marlinspike, Marcello Salvati

upgrading scipy in mac

I want to upgrade scipy. and I used pip install scipy --upgrade to do this, but here is error, how should I fix this?
Installing collected packages: scipy
Found existing installation: scipy 0.13.0b1
DEPRECATION: Uninstalling a distutils installed project (scipy) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling scipy-0.13.0b1:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 778, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/7x/1ly_pjjd3g50632kc7mc68n00000gn/T/pip-a37H18-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy-0.13.0b1-py2.7.egg-info'
Python version 2.7.10
Mac version 10.12.04
I tried to install face_recognition, then display the same problem.
sudo pip install face_recognition
try use:
sudo pip install --upgrade scipy --ignore-installed six

Failed uninstall/install of Smartsheet Python SDK

I ran into some issues with the Python SDK. I figured before opening a bug up I'd see if reinstalling would help with any updates. I ran sudo pip uninstall smartsheet-python-sdk and it failed at about 90% trying to uninstall the python-dateutil package. I then reinstalled the smartsheet SDK and it failed to work. I then reinstalled requests, requests-toolbelt, six, certified, python-dateutil and the SDK; using the --force-install and then --ignore-installed to try to reset things. When I run a script that worked before all the installs I get the following error:
Traceback (most recent call last):
File "./smytest.py", line 212, in <module>
SMUTrackerSmartsheet=smartsheet.Sheets.get_sheet(SMARTSHEET_SMU_TRACKER_SHEET_ID)
File "/Library/Python/2.7/site-packages/smartsheet/sheets.py", line 460, in get_sheet
response = self._base.request(prepped_request, expected, _op)
File "/Library/Python/2.7/site-packages/smartsheet/smartsheet.py", line 178, in request
res = self.request_with_retry(prepped_request, operation)
File "/Library/Python/2.7/site-packages/smartsheet/smartsheet.py", line 242, in request_with_retry
return self._request(prepped_request, operation)
File "/Library/Python/2.7/site-packages/smartsheet/smartsheet.py", line 210, in _request
raise UnexpectedRequestError(rex.request, rex.response)
smartsheet.exceptions.UnexpectedRequestError: (<PreparedRequest [GET]>, None)
Is there a way to reinstall the SDK to properly catch and set any dependancies I'm missing?
I faced a similar error.
You might want to do see if the package is installed there. Try this:
pip freeze
The trick is to add "-H" to the sudo command, run:
sudo -H pip uninstall smartsheet-python-sdk
Now check to see if it was uninstalled:
pip freeze
Next install by the following:
pip install smartsheet-python-sdk
Hope this helps.