pip uninstall namespace subpackage - python-2.7

How can I uninstall with pip one of the distributions which provide subpackages of a namespace package without breaking programs which only use subpackages of this namespace package from the remaining distributions?
I have 2 distributions (distribution{1,2}) providing 2 subpackages (package{1,2}) of a namespace package (namespace1):
distribution1/namespace1/__init__.py:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
distribution1/namespace1/package1/__init__.py:
from module1 import function1
distribution1/namespace1/package1/module1.py:
def function1():
pass
distribution1/setup.py:
from setuptools import find_packages, setup
setup(
name="distribution1",
version="0.1",
packages=find_packages())
distribution2/namespace1/__init__.py:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
distribution2/namespace1/package2/__init__.py:
from module2 import function2
distribution2/namespace1/package2/module2.py:
def function2():
pass
distribution2/setup.py:
from setuptools import find_packages, setup
setup(
name="distribution2",
version="0.1",
packages=find_packages())
And a test program:
main.py:
from namespace1.package1 import function1
function1()
When I install both distributions and uninstall one of them (distribution2), the example program fails:
% for i in distribution* ; do ( cd $i ; pip install . ) ; done
Processing .../distribution1
Installing collected packages: distribution1
Running setup.py install for distribution1
Successfully installed distribution1-0.1
Processing .../distribution2
Installing collected packages: distribution2
Running setup.py install for distribution2
Successfully installed distribution2-0.1
% python main.py
% pip uninstall -y distribution2
Uninstalling distribution2-0.1:
Successfully uninstalled distribution2-0.1
% python main.py
Traceback (most recent call last):
File "main.py", line 1, in <module>
from namespace1.package1 import function1
ImportError: No module named namespace1.package1
It works when "pip install --egg ." was used in the distribution source folder. But since eggs are considered deprecated in favor of wheels, is there a solution without this "--egg" option?
Environment:
Python 2.7.9
setuptools 14.3.1
pip 6.1.1
wheel 0.24.0

Related

No module named torch.distributed

ImportError: No module named torch.distributed
File "train.py", line 4, in <module>
import torch.distributed as dist
ImportError: No module named torch.distributed
I installed CUDA AND cuDNN then created env and installed pip3 install torch torchvision but getting error.
This works for me:
Create a conda virtual environment:
conda create -n env_pytorch python=3.6
Active this environment create above:
source activate env_pytorch
Install PyTorch with pip or pip3:
pip install torchvision --user

H5PY installed, but does not import

I am trying to import H5PY in my Python code, but the module cannot be found. I am using Ubuntu 16.04 and Python 2.7.
I have tried reinstalling h5py both with conda and with pip and individually and the following
sudo pip install cython
sudo apt-get install libhdf5-dev
sudo pip install h5py
but it still does not work.
Installing h5py tells me that it is already installed in /anaconda2/lib/python2.7/site-packages.
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/snap/pycharm-community/128/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named h5py
Has anyone fixed this problem?
I found my solution!
I added found out the path where h5py is installed and added it to the path where python looks for the modules with
import sys
sys.path.append("mypath")
Hope this also helps others
For me the following worked:
sudo apt-get update
sudo apt-get install python3-h5py
Ref: https://www.devmanuals.net/install/ubuntu/ubuntu-16-04-LTS-Xenial-Xerus/how-to-install-python3-h5py.html

How to resolve ImportError: No module named urls

I get this error whenever I run my code:
File "...", line 6, in <module> from django.urls import reverse
ImportError: No module named urls
So I look at that file and check the line and it says that this has an error:
from django.urls import reverse
I don't know where the error is coming from because when I delete the line of code, it returns me this error:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I also tried adding MySQLdb in the interpreter but this time, it gives me this error:
Non-zero exit code (1)
please confirm the from django.conf.urls import include, url is added in your header or not.
For MySQl error, you may need to install the Python and MySQL.
sudo apt-get install python-dev default-libmysqlclient-dev #Ubuntu
Then install the mysql client using pip command.
pip install mysqlclient # for python 2.x
pip3 install mysqlclient # for python 3.x
Finally
pip install PyMySQL #for python 2.x
pip3 install PyMySQL #for python 3.x

ImportError: matplotlib requires dateutil- python

I get this error when i try to import matplotlib. I have installed matplotlib.
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
import matplotlib
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 110, in <module>
raise ImportError("matplotlib requires dateutil")
ImportError: matplotlib requires dateutil
how do I solve this problem?
matplotlib depends on dateutil
On Linux you can install it using
pip install python-dateutil
You can reinstall them forcefully using
pip install python-dateutil --force-reinstall --upgrade
To install pip on windows get the script get-pip.py from here. Then on cmd run
python get-pip.py

ImportError: cannot import name CSafeLoader

Installed all the dependencies for juju
pip install pyparsing==1.5.7
pip install pyOpenSSL PyYAML txaws pydot oauth txzookeeper zc-zookeeper-static
pip install juju
All installed fine but when I start juju, fails with the following error:
(jujuapp) ± juju
Traceback (most recent call last):
File "/Users/millisami/.virtualenvs/jujuapp/bin/juju", line 4, in <module>
from juju.control import main
File "/Users/millisami/.virtualenvs/jujuapp/lib/python2.7/site-packages/juju/control/__init__.py", line 7, in <module>
from .utils import ParseError
File "/Users/millisami/.virtualenvs/jujuapp/lib/python2.7/site-packages/juju/control/utils.py", line 8, in <module>
from juju.state.environment import EnvironmentStateManager
File "/Users/millisami/.virtualenvs/jujuapp/lib/python2.7/site-packages/juju/state/environment.py", line 8, in <module>
from juju.environment.config import EnvironmentsConfig
File "/Users/millisami/.virtualenvs/jujuapp/lib/python2.7/site-packages/juju/environment/config.py", line 8, in <module>
from juju.lib import serializer
File "/Users/millisami/.virtualenvs/jujuapp/lib/python2.7/site-packages/juju/lib/serializer.py", line 1, in <module>
from yaml import CSafeLoader, CSafeDumper, Mark
ImportError: cannot import name CSafeLoader
What is this error?
I'm on Mac 10.6, python and pip installed via homebrew.
I just ran into this issue on 10.8; juju uses the libyaml bindings in PyYaml, so it needs to have PyYaml installed --with-libyaml, which requires more than that on the mac. Here's how I got it working:
brew install libyaml with homebrew
Download PyYaml source (instructions)
Now modify [pyyaml-install-dir]/setup.cfg like this:
# List of directories to search for 'yaml.h' (separated by ':').
include_dirs=/usr/local/Cellar/libyaml/0.1.4/include/
# List of directories to search for 'libyaml.a' (separated by ':').
library_dirs=/usr/local/Cellar/libyaml/0.1.4/lib/
So it can find your homebrew installation of libyaml. Then you also need to install Cython..
sudo pip install cython
and finally..
sudo python setup.py --with-libyaml install (in the PyYaml dir)
Now juju should work!