19

I have only very rudimentary experience in Python. I am trying to install the package pyslim (see here on the pypi website). I did

$ pip install pyslim

Requirement already satisfied: pyslim in ./Library/Python/2.7/lib/python/site-packages/pyslim-0.1-py2.7.egg (0.1)
Requirement already satisfied: msprime in /usr/local/lib/python2.7/site-packages (from pyslim) (0.6.1)
Requirement already satisfied: attrs in /usr/local/lib/python2.7/site-packages (from pyslim) (16.3.0)
Requirement already satisfied: svgwrite in /usr/local/lib/python2.7/site-packages (from msprime->pyslim) (1.1.12)
Requirement already satisfied: jsonschema in /usr/local/lib/python2.7/site-packages (from msprime->pyslim) (2.6.0)
Requirement already satisfied: six in /usr/local/lib/python2.7/site-packages (from msprime->pyslim) (1.10.0)
Requirement already satisfied: numpy>=1.7.0 in /usr/local/lib/python2.7/site-packages/numpy-1.10.4-py2.7-macosx-10.11-x86_64.egg (from msprime->pyslim) (1.10.4)
Requirement already satisfied: h5py in /usr/local/lib/python2.7/site-packages (from msprime->pyslim) (2.8.0)
Requirement already satisfied: pyparsing>=2.0.1 in /usr/local/lib/python2.7/site-packages (from svgwrite->msprime->pyslim) (2.2.0)
Requirement already satisfied: functools32; python_version == "2.7" in /usr/local/lib/python2.7/site-packages (from jsonschema->msprime->pyslim) (3.2.3.post2)

But when I open python and try to import pyslim, it fails

> import pyslim

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/remi/Library/Python/2.7/lib/python/site-packages/pyslim-0.1-py2.7.egg/pyslim/__init__.py", line 4, in <module>
    from pyslim.slim_metadata import *       # NOQA
  File "/Users/remi/Library/Python/2.7/lib/python/site-packages/pyslim-0.1-py2.7.egg/pyslim/slim_metadata.py", line 1, in <module>
    import attr
ImportError: No module named attr

So, I did

$ pip install attr
Requirement already satisfied: attr in /usr/local/lib/python2.7/site-packages (0.3.1)

and

$ pip install attrs
Requirement already satisfied: attrs in /usr/local/lib/python2.7/site-packages (16.3.0)

I restarted python and tried to import pyslim again but I keep receiving the same error message. I also tried to download and install the files from github by doing

$ git clone https://github.com/tskit-dev/pyslim.git
$ cd pyslim
$ python setup.py install --user

as indicated here on the pypi website. On this last line of code, I get a long output ending with

Download error on https://pypi.python.org/simple/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found!
No local packages or download links found for attrs
error: Could not find suitable distribution for Requirement.parse('attrs')

I am using Python 2.7.10 on a MAC OSX 10.11.6. Not sure if it matter but I usually install things with homebrew. I am using pip 18.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7).

Edit

$ which python
   /usr/bin/python
$ which pip
   /usr/local/bin/pip
Remi.b
  • 17,389
  • 28
  • 87
  • 168
  • 6
    A comment for the down vote would be very welcome! – Remi.b Oct 09 '18 at 21:53
  • 1
    you might have installation conflict problem, of macos default python & homebrew python. try these command in terminal to see which one is being used `which python` & `which pip` – deadvoid Oct 09 '18 at 22:06
  • @cryptonome Thanks. See edit – Remi.b Oct 09 '18 at 22:08
  • compare those paths to the ones in your error messages. when you run `python` in your terminal, you were invoking system's default python, while when you installed the module & deps with pip, you installed to homebrew's python installation. i suspect the downvotes were because there's a lot of similar questions in here that dealt with the same problem. – deadvoid Oct 09 '18 at 22:12
  • @cryptonome Ah indeed! I see the issue. I removed the `/usr/local/lib/python2.7` and now `pip` cannot find python in `/usr/bin/python` (it throws `ImportError: No module named pip._internal`). I am currently trying to find a way to solve that and I suppose it should then work all fine. – Remi.b Oct 09 '18 at 22:20
  • @cryptonome Despite many posts that have similar title, I failed to find one that was helpful to me. But I might have not looked hard enough or maybe similar trouble have arose via different error messages leading to posts that are phrased quite differently. Thanks for explaining the potential reason for a closed vote. – Remi.b Oct 09 '18 at 22:22
  • one caution, _do not remove system's python_, it's used by macos, you probably will end up having to reinstall your os if that happens. just use homebrews python as your interpreter, and utilize virtual environment to contain your projects. – deadvoid Oct 09 '18 at 22:23
  • 1
    You might be able to work around the problem by appending your PYTHON_PATH in your bash profile, something like this: `export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages` – Swagga Ting Oct 09 '18 at 22:30
  • 1
    Hi, you installed two packages that might lead to conflict problems. 1. please uninstall attr and attrs package `pip uninstall attr && pip uninstall attrs ` 2. install attrs `pip install attrs` – Nwawel A Iroume Jan 23 '20 at 11:20

3 Answers3

12

Unsure if OP was able to resolve this, but I recently came across this error while starting a scrapy shell and I resolved it by upgrading attrs.

pip install --upgrade attrs

Some snooping led me to understand that this is because sometimes python libraries are too lax with the version of attrs that they ask for.

Ketaki Lolage
  • 121
  • 1
  • 2
7

Take a look to this other question that is related to the attrs package.

In your case, you have attr and attrs installed at the same time, and they are incompatible between them, so python is unable to resolve the package name on the import correctly.

You should use attrs only, so try uninstalling attr and try it again:

python -m pip uninstall attr

If, in the future, you need to have some packages incompatibles between them, take a look about using virtual environments in Python, which are really easy to use and will be very useful to play with packages and packages versions without break anything.

Jofre
  • 3,718
  • 1
  • 23
  • 31
Latra
  • 492
  • 3
  • 14
-1

First uninstall pyslim. Use "pip uninstall pyslim". Then try installing again using "conda install -c conda-forge pyslim"

Refer https://anaconda.org/conda-forge/pyslim