Skip to content

Commit

Permalink
ugly fix for msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes committed Dec 1, 2018
1 parent 9675487 commit 4c0452a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,12 @@ Package is available on PyPI, can be installed with:
pip install hpfrec
```

**Note: at the moment, the latest versions will not compile under Visual Studio in Windows, but you can nevertheless install an older version like this:**
```
pip install hpfrec==0.2.2.5
```

As it contains Cython code, it requires a C compiler. In Windows, this usually means it requires a Visual Studio installation (or MinGW + GCC), and if using Anaconda, might also require configuring it to use said Visual Studio instead of MinGW, otherwise the installation from `pip` might fail. For more details see this guide:
[Cython Extensions On Windows](https://github.com/cython/cython/wiki/CythonExtensionsOnWindows)

On Python 2.7 on Windows, it might additionally require installing extra Visual Basic modules (untested).

On Linux and Mac, the `pip` install should work out-of-the-box, as long as the system has `gcc` (included by default in most installs).
On Linux and Mac, the `pip` install should work out-of-the-box, as long as the system has `gcc`.

## Sample usage

Expand Down
60 changes: 44 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import numpy
import platform

## Note: As of the end of 2018, MSVC is still stuck with OpenMP 2.0 (released 2002), which does not support
## parallel for loops with unsigend iterators. If you are using a different compiler, this part can be safely removed
if platform.system() == "Windows":
import re
fout = open("temp1.txt", "w")
with open("hpfrec\\cython_loops.pyx", "r") as fin:
for line in fin:
fout.write(re.sub("size_t([^\w])", "long\\1", line))
fout.close()
fout = open("temp2.txt", "w")
with open("hpfrec\\__init__.py", "r") as fin:
for line in fin:
fout.write(re.sub("size_t([^\w])", "long\\1", line))
fout.close()

fout = open("hpfrec\\cython_loops.pyx", "w")
with open("temp1.txt", "r") as fin:
for line in fin:
fout.write(line)
fout.close()
fout = open("hpfrec\\__init__.py", "w")
with open("temp2.txt", "r") as fin:
for line in fin:
fout.write(line)
fout.close()


## https://stackoverflow.com/questions/724664/python-distutils-how-to-get-a-compiler-that-is-going-to-be-used
class build_ext_subclass( build_ext ):
Expand All @@ -20,22 +48,22 @@ def build_extensions(self):
build_ext.build_extensions(self)

setup(
name = 'hpfrec',
packages = ['hpfrec'],
install_requires=[
'pandas>=0.21',
'numpy',
'scipy',
'cython'
name = 'hpfrec',
packages = ['hpfrec'],
install_requires=[
'pandas>=0.21',
'numpy',
'scipy',
'cython'
],
version = '0.2.2.9',
description = 'Hierarchical Poisson matrix factorization for recommender systems',
author = 'David Cortes',
author_email = 'david.cortes.rivera@gmail.com',
url = 'https://github.com/david-cortes/hpfrec',
keywords = ['poisson', 'probabilistic', 'non-negative', 'factorization', 'variational inference', 'collaborative filtering'],
classifiers = [],
version = '0.2.2.10',
description = 'Hierarchical Poisson matrix factorization for recommender systems',
author = 'David Cortes',
author_email = 'david.cortes.rivera@gmail.com',
url = 'https://github.com/david-cortes/hpfrec',
keywords = ['poisson', 'probabilistic', 'non-negative', 'factorization', 'variational inference', 'collaborative filtering'],
classifiers = [],

cmdclass = {'build_ext': build_ext_subclass},
ext_modules = [Extension("hpfrec.cython_loops", sources=["hpfrec/cython_loops.pyx"], include_dirs=[numpy.get_include()])]
cmdclass = {'build_ext': build_ext_subclass},
ext_modules = [Extension("hpfrec.cython_loops", sources=["hpfrec/cython_loops.pyx"], include_dirs=[numpy.get_include()])]
)

0 comments on commit 4c0452a

Please sign in to comment.