ProjectQ-Framework / ProjectQ

ProjectQ: An open source software framework for quantum computing
https://projectq.ch
Apache License 2.0
888 stars 274 forks source link

Package installation is not working #74

Closed Strilanc closed 7 years ago

Strilanc commented 7 years ago

When I run the install commands given in the documentation:

python -m pip install --user projectq

or:

sudo apt-get install build-essential python3 python3-pip
sudo pip3 install --user projectq

The install fails with multiple distinct errors:

    [...]
        ImportError: No module named pybind11
    [...]
        Command [...]/bin/python -c "import setuptools, tokenize;[...] failed with error code 1 [...]
    [...]
      File "[...]/pip/basecommand.py", line 161, in main
      UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 42: ordinal not in range(128)

I think the first two errors are because the documentation says I need to install "build tools" but doesn't actually say what they are or how to install them. So I wasn't able to do that. (I do have g++ installed.) But the third error looks typical of a python2 data-vs-str encoding issue.

Strilanc commented 7 years ago

Interestingly, when I separately run sudo pip3 install pybind11, then sudo pip3 install projectq starts to work.

Maybe the package is not correctly specifying pybind11 as a dependency?

Strilanc commented 7 years ago

Repro steps:

mkvirtualenv tmp
pip install projectq   #FAILS

pip install pybind11
pip install projectq   #WORKS
damiansteiger commented 7 years ago

pybind11 is correctly included in the requirements.txt:

https://github.com/ProjectQ-Framework/ProjectQ/blob/master/requirements.txt

Strilanc commented 7 years ago

Any ideas why pip install projectq would switch from failing to succeeding after installing pybind?

thomashaener commented 7 years ago

I have no clue and I think it's really weird that pip does not install pybind despite it being a requirement.

Strilanc commented 7 years ago

Matthew thinks it's because of line 30 in setup.py, which has to build an Extension that uses pybind11. But this is before the setup call that actually installs pybind11.

maffoo commented 7 years ago

It looks like this could work if we could tell pip to install the required libraries before building the extension module.

Strilanc commented 7 years ago

Line 146 creates an exception but doesn't raise it?

maffoo commented 7 years ago

I think there might be a problem with the 0.2.0 package that was uploaded to pypi. If I checkout git master and do pip install . it works. But pip install projectq fails in the way @Strilanc mentioned, and it also fails if I download the 0.2.0 tarfile from pypi and try to run pip install . there.

Edit: false alarm; the 0.2.0 tarfile seems to behave the same as master, so at least the uploaded archive matches git. Still a problem with getting the version from pypi, however.

maffoo commented 7 years ago

Ok, I think I see the problem. As of version 6.0.1, pip does a topological sort on dependencies before installing them, so that dependencies of package foo get installed before foo itself. Prior versions of pip did not make this guarantee. If I create a new virtualenv on my system (ubuntu 14.04) I get the ancient system version of pip, version 1.5.4. In that case after collecting all the packages, pip says:

Installing collected packages: projectq, numpy, future, pytest, pybind11, requests, py
  Running setup.py install for projectq

So basically it is trying to install projectq before pybind11, which fails. The solution is to update pip itself in the virtualenv:

$ pip install --upgrade pip

Then when I run pip install projectq I get the following:

Installing collected packages: numpy, future, py, pytest, pybind11, requests, projectq

Crucially, it installs pybind11 before projectq and everything works fine.

Strilanc commented 7 years ago

I notice a lot of install instructions often start with pip install --upgrade pip, presumably because of stuff like this... makes me think the package should really be able to declare a minimum version of pip.

thomashaener commented 7 years ago

Thanks @Strilanc and @maffoo, this is good to know. Also, I added the missing 'raise' in setup.py. Thanks for pointing this out!

maffoo commented 7 years ago

My only other suggestion would be to add a note in the tutorial to let users know they might need to update pip before installing projectq itself. Aside from that I think we can close this issue.