Install needed libraries for Weasyprint on pipenv (Windows environment) - python

In order to start generating documents with Weasyprint I installed it on my Windows machine following these instructions:
https://weasyprint.readthedocs.io/en/stable/install.html#step-5-run-weasyprint
On my computer it works but I have a Django project where I want to integrate this library and I use pipenv. How to install the necessary libraries even in the virtual environment?
I tried setting the path for the pycairo package into the Pipfile like
pycairo= {path= "C:/Program Files/GTK3-Runtime Win64/bin/"}
but still it throws the error:
OSError: dlopen() failed to load a library: cairo / cairo-2 / cairo-gobject-2 / cairo.so.2
I have 64bit Windows machine and this is the Pipfile:
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
pylint = "*"
[packages]
django = "*"
mysql = "*"
ipython = "*"
django-webpack = "*"
django-webpack-loader = "*"
django-livereload-server = "*"
pylint = "*"
reportlab = "*"
weasyprint = "*"
django-weasyprint = "*"
pycairo= {path= "C:/Program Files/GTK3-Runtime Win64/bin/"}
cairocffi = "*"
[requires]
python_version = "3.7"

You need install 'GTK+ 64 Bit Installer' path in this local:
C:\msys2
Source: WeasyPrint Github

I came across this error as well and followed every step mentioned in the Weasyprint docs for the installation. I was using PowerShell as my default terminal and pipenv. First I tried using the command import weasyprint inside python shell in my virtualenv, but it always returned the cairo, dlopen() etc error.
What worked for me was switching to cmd. Switched and used the same commands and now it's executing perfectly.
Also, in my pipfile, for weasyprint, which is enough to generate a report in django, I only have weasyprint installed. In the question, if it is still relevant for someone, the libraries reportlab, django-weasyprint, pycairo and cairocffi can be safely removed/uninstalled from pipenv.

Please type the following command:
WHERE libcairo-2.dll
you should be getting 'C:\msys2\mingw64\bin\libcairo-2.dll'
then open your cmd and type the following.
SET PROPER_GTK_FOLDER=
SET PATH=%PROPER_GTK_FOLDER%;%PATH%
Please follow the documentation it has everything to run on windows. It worked for me it i hope it will work for youenter link description here

Related

Poetry - Add windows shared drive as source for python package

I am failing to install a python dependency from a Windows shared drive. This is what the relevant section of the pyproject.toml looks like
[[tool.poetry.source]]
name = "repo"
url = "\\\\myserver.eu.org\\path\\to\\python_packages"
default = false
secondary = true
[tool.poetry.dependencies]
python = "^3.8"
package_from_repo = "*"
When I try poetry install it tells me package_from_repo (*) which doesn't match any versions, version solving failed
I can successfully install the package with pip using the following pip.ini config
[install]
find-links =
\\myserver.eu.org\path\to\python_packages
I am using poetry version 1.2.0 on Windows 10 Enterprise (x64). As terminal I use Powershell.

How to `pipenv uninstall` a package installed from an archive file on the web?

I started to use pipenv a few days ago. I have installed a 2.0.0 version of a library, I did:
pipenv intall https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.0.0/es_core_news_sm-2.0.0.tar.gz#egg=es_core_news_sm
Then I realized I need a 2.3.0 version, so I did
pip install https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.3.0/es_core_news_sm-2.3.0.tar.gz#egg=es_core_news_sm
And I would like to remove the previous one (2.0.0), so:
pipenv uninstall https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.0.0/es_core_news_sm-2.0.0.tar.gz
Un-installing https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.0.0/es_core_news_sm-2.0.0.tar.gz…
No package https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.0.0/es_core_news_sm-2.0.0.tar.gz to remove from Pipfile.
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
So it looks like pipenv did not remove the first version. The Pipfile still has lines for both:
[packages.f8ba4b6]
file = "https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.0.0/es_core_news_sm-2.0.0.tar.gz"
[packages.0feb3d5]
file = "https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.3.0/es_core_news_sm-2.3.0.tar.gz"
And so does the Pipfile.lock:
"default": {
"0feb3d5": {
"file": "https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.3.0/es_core_news_sm-2.3.0.tar.gz"
},
"f8ba4b6": {
"file": "https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.0.0/es_core_news_sm-2.0.0.tar.gz"
}
}
I also tried uninstalling them like this:
pipenv uninstall es_core_news_sm en_core_web_sm
Un-installing es_core_news_sm…
Found existing installation: es-core-news-sm 2.3.0
Uninstalling es-core-news-sm-2.3.0:
Successfully uninstalled es-core-news-sm-2.3.0
No package es_core_news_sm to remove from Pipfile.
Un-installing en_core_web_sm…
Found existing installation: en-core-web-sm 2.2.0
Uninstalling en-core-web-sm-2.2.0:
Successfully uninstalled en-core-web-sm-2.2.0
But the Pipenv still has the lines with the 2.0.0 version (the ones, I've pasted above).
So far I have removed the obsolete 2.0.0 entry from Pipfile, then pipenv locked and now the Pipfile.lock does not have the 2.0.0 entry. I however, wonder if the package is still in my .venv, poor lost soul.
Have you tried looking in the virtual environment folder?
pipenv -venv
In my experience, the pipenv install/uninstall command only works for packages listed under [packages] and [dev-packages]. Somehow your install command generated another section - so it seems like you did the right thing just to remove it. If you install again using the same command as above:
pipenv install https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.0.0/es_core_news_sm-2.0.0.tar.gz#egg=es_core_news_sm
You should end up with something like this:
[packages]
es-core-news-sm = {file = "https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.0.0/es_core_news_sm-2.0.0.tar.gz"}

Installing TensorFlow with pipenv gives error

I'm trying to install TensorFlow using pipenv.
This is my Pipfile:
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
pylint = "*"
[packages]
python-telegram-bot = "*"
imdbpy = "*"
matplotlib = "*"
scikit-image = "*"
scikit-learn = "*"
tensorflow = "*"
[requires]
python_version = "3.8"
I then run:
pipenv install tensorflow
Which outputs:
Installing tensorflow…
Adding tensorflow to Pipfile's [packages]…
Installation Succeeded
Pipfile.lock (989c3d) out of date, updating to (0d6760)…
Locking [dev-packages] dependencies…
Success!
Locking [packages] dependencies…
Locking Failed!
Followed by a big traceback that ends with:
pipenv.patched.notpip._internal.exceptions.InstallationError: Command "python setup.py egg_info" failed with error code 1 in C:\Users\lucas\AppData\Local\Temp\tmpyh639mq4build\functools32\
My virtual environment uses Python 3.8.0 64 bit.
What am I doing wrong?
As the comments pointed out, Tensorflow only supports up to python 3.7 (as March 2020). You can find more info in the system requirements page of the documentation.
So, to fix your issue:
Remove the virtual environment with pipenv --rm
Remove the Pipfile.lock
Change the last lines of your Pipfile to
[requires]
python_version = "3.7"
Run pipenv install --dev to recreate the environment again and pipenv install tensorflow to install tensorflow
Done!

Pipenv: dependencies of platform specific packages are installed unconditionally?

I am trying to integrate pipenv into my new project because I need to have some dependencies for development only and I couldn't find an easy way to have additional dev dependencies with pip or venv.
However, I ran into an issue when trying it:
My project depends on pypiwin32 when it's used in windows. Because it's a windows dependency, I installed it with the command:
pipenv install "pypiwin32 ; platform_system == 'Windows'"
which succesfully added this dependency to my Pipfile with the platform restriction:
# Pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
# dependencies...
[packages]
# dependencies...
pypiwin32 = {markers = "platform_system == 'Windows'",version = "*"}
[requires]
python_version = "3.7"
The problem is that pypiwin32 depends on the pywin32 package and when I looked in the Pipfile.lock file I saw that it's not restricted to windows only:
# Pipfile.lock
"pypiwin32": {
"index": "pypi",
"markers": "platform_system == 'Windows'",
"version": "==223"
},
"pywin32": {
"version": "==224"
},
which is weird. I tested it by changing the restriction to 'Linux' and trying to install the dependencies into a new environment without the Pipfile.lock and it ignored pypiwin32 as expected but it installed pywin32 anyway despite the fact that it's not listed in the Pipfile and that it's a dependency of a package which was ignored.
This is a serious problem because if I decide to deploy or develop on a linux machine, it will simply not work because pywin32 isn't available on linux or mac (as far as I know).
Is there a way to correctly mark the dependencies of a package with the restrictions of the package?
I don't want to manually edit Pipfile.lock (I also don't think it will work because when I tried to install it into a new environment, I copied the Pipfile only).
Alternatively, is there a better way to manage my dependencies? I need the ability to specify development dependencies that won't be installed on a production environment and I need the ability to specify platform specific dependencies. pip with the requirements.txt can't handle the first request as far as I know, which is why I tried switching to pipenv.
I tried looking it up with no success. Any help would be appreciated.
Adding platform specific installation of both pypiwin32 and pywin32 packages explicitly in the pipfile should solve the issue.
pypiwin32 = {version = "*", sys_platform = "== 'win32'"}
pywin32 = {version = "*", sys_platform = "== 'win32'"}
The prerequisite package pywin32 will in that case also be ignored on linux.

Using zc.buildout, how do I install a tarball from a website?

I'm trying to get zc.buildout to install Gunicorn from source. Using the following configuration:
[gunicorn]
recipe = collective.recipe.distutils
url = http://github.com/benoitc/gunicorn/tarball/master
results in the following error:
SystemError: ('Failed', '"/usr/bin/python" setup.py -q install --install- purelib="/mnt/hgfs/Projects/intranation/parts/site-packages" --install-platlib="/mnt/hgfs/Projects/intranation/parts/site-packages"')
Providing a --install-dir or --prefix doesn't help.
Is there a recipe for zc.buildout that downloads a tarball and installs it via easy_install or similar?
You can "just" install it. On the command line, "easy_install http://github.com/benoitc/gunicorn/tarball/master" works fine.
The buildout equivalent would be to have a dependency on "gunicorn" (so that buildout attempts installing it) and to tell buildout that your github link is actually gunicorn. You do that with find-links:
[buildout]
find-links =
http://github.com/benoitc/gunicorn/tarball/master#egg=gunicorn
parts = console_scripts
[console_scripts]
recipe = zc.recipe.egg
eggs = gunicorn

Categories