Skip to content

Commit b10975a

Browse files
Installation refactored - Attempt for issue #532 (#534)
* Update requirements.txt * Readme updated with the newest installation commands * Installation Workflow Redesigned with ReadTheDocs Config Added * Error fix in __init__ * Codacy Issues Fixed * Error fix when TL installed from PyPI or Wheel file without Tensorflow * Codacy Error Fix + YAPF Error Fix
1 parent 2865e36 commit b10975a

File tree

7 files changed

+105
-47
lines changed

7 files changed

+105
-47
lines changed

.readthedocs.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
formats:
2+
- epub
3+
- pdf
4+
5+
python:
6+
version: 3.6
7+
pip_install: true
8+
extra_requirements:
9+
- doc
10+
- dev
11+
- test

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ env:
2121

2222

2323
install:
24-
- pip install tensorflow
25-
- pip install -r requirements.txt
26-
- pip install -e .[dev,doc,test]
24+
- pip install -e .[tf_cpu,dev,test,doc]
2725

2826

2927
script:

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,38 @@ The simplest way to install TensorLayer is:
6666
# for master version (Recommended)
6767
$ pip install git+https://github.com/tensorlayer/tensorlayer.git
6868

69-
# for stable version
69+
# for last stable version
7070
$ pip install tensorlayer
71+
72+
# for latest release candidate
73+
$ pip install --pre tensorlayer
74+
```
75+
76+
If you prefer to build from sources in a development objective
77+
```bash
78+
# First clone the repository
79+
$ git clone https://github.com/tensorlayer/tensorlayer.git
80+
$ cd tensorlayer
81+
82+
# Install virtualenv if necessary
83+
$ pip install virtualenv
84+
85+
# Then create a virtualenv called venv inside
86+
$ virtualenv venv
87+
88+
# Activate the virtualenv
89+
90+
# Linux:
91+
$ source venv/bin/activate
92+
93+
# Windows:
94+
$ venv\Scripts\activate.bat
95+
96+
# for a machine **without** an NVIDIA GPU
97+
$ pip install -e .[tf_cpu,dev,test,doc]
98+
99+
# for a machine **with** an NVIDIA GPU
100+
$ pip install -e .[tf_gpu,dev,test,doc]
71101
```
72102

73103
Dockerfile is supplied to build images, build as usual
@@ -80,6 +110,12 @@ $ docker build -t tensorlayer:latest .
80110
$ docker build -t tensorlayer:latest-gpu -f Dockerfile.gpu .
81111
```
82112

113+
Launching the unittest:
114+
115+
```bash
116+
$ pytest
117+
```
118+
83119
Please check [documentation](http://tensorlayer.readthedocs.io/en/latest/user/installation.html) for detailed instructions.
84120

85121

docs/requirements-rtd.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# Keep this file in sync with requirements-rtd.txt, except tensorflow
2-
31
flake8-docstrings>=1.3,<1.4
42
matplotlib>=2.2,<2.3
53
pymongo>=3.6,<3.7
64
progressbar2>=3.37,<3.38
75
scikit-image>=0.13,<0.14
86
scipy>=1.0,<1.1
97
sphinx>=1.7,<1.8
10-
tensorflow>=1.7,<1.8

setup.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
else:
4242
long_description = 'See ' + __homepage__
4343

44-
4544
# ======================= Reading Requirements files as TXT files =======================
4645

4746
def req_file(filename):
@@ -51,6 +50,24 @@ def req_file(filename):
5150
# Example: `\n` at the end of each line
5251
return [x.strip() for x in content]
5352

53+
# ======================= Defining the requirements var =======================
54+
55+
install_requires = req_file("requirements.txt")
56+
57+
extras_require = {
58+
'tf_cpu': ['tensorflow>=1.8.0,<1.9'],
59+
'tf_gpu': ['tensorflow-gpu>=1.8.0,<1.9'],
60+
'dev': req_file("requirements_dev.txt"),
61+
'doc': req_file("docs/requirements.txt"),
62+
'test': req_file("tests/requirements.txt")
63+
}
64+
65+
# Readthedocs requires TF 1.5.0 to build properly
66+
if os.environ.get('READTHEDOCS', None) == 'True':
67+
install_requires.append("tensorflow==1.5.0")
68+
69+
# ======================= Define the package setup =======================
70+
5471
setup(
5572
name=__package_name__,
5673

@@ -125,16 +142,12 @@ def req_file(filename):
125142
# your project is installed. For an analysis of "install_requires" vs pip's
126143
# requirements files see:
127144
# https://packaging.python.org/en/latest/requirements.html
128-
install_requires=req_file("requirements.txt"),
145+
install_requires=install_requires,
129146

130147
# List additional groups of dependencies here (e.g. development
131148
# dependencies). You can install these using the following syntax,
132149
# $ pip install -e .[test]
133-
extras_require={
134-
'dev': req_file("requirements_dev.txt"),
135-
'doc': req_file("docs/requirements.txt"),
136-
'test': req_file("tests/requirements.txt")
137-
},
150+
extras_require=extras_require,
138151
scripts=[
139152
'tl',
140153
],

tensorlayer/__init__.py

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,44 @@
33
"""Deep learning and Reinforcement learning library for Researchers and Engineers"""
44
from __future__ import absolute_import
55

6-
try:
6+
import pkg_resources
7+
installed_packages = [d for d in pkg_resources.working_set]
8+
9+
TF_is_installed = False
10+
TL_is_installed = False
11+
12+
for package in installed_packages:
13+
if 'tensorflow' in package.project_name:
14+
TF_is_installed = True
15+
if 'tensorlayer' in package.project_name and 'site-packages' in package.location:
16+
TL_is_installed = True
17+
18+
if TF_is_installed: # The tensorlayer package is installed
719
import tensorflow
8-
except ImportError:
20+
21+
from . import activation
22+
from . import cost
23+
from . import files
24+
from . import iterate
25+
from . import layers
26+
from . import models
27+
from . import utils
28+
from . import visualize
29+
from . import prepro
30+
from . import nlp
31+
from . import rein
32+
from . import distributed
33+
34+
# alias
35+
act = activation
36+
vis = visualize
37+
38+
global_flag = {}
39+
global_dict = {}
40+
41+
elif TL_is_installed:
942
install_instr = "Please make sure you install a recent enough version of TensorFlow."
10-
raise ImportError("__init__.py : Could not import TensorFlow." + install_instr)
11-
12-
from . import activation
13-
from . import cost
14-
from . import files
15-
from . import iterate
16-
from . import layers
17-
from . import models
18-
from . import utils
19-
from . import visualize
20-
from . import prepro
21-
from . import nlp
22-
from . import rein
23-
from . import distributed
24-
25-
# alias
26-
act = activation
27-
vis = visualize
43+
raise ImportError("__init__.py : Could not import TensorFlow. {}".format(install_instr))
2844

2945
# Use the following formating: (major, minor, patch, prerelease)
3046
VERSION = (1, 8, 5, 'rc2')
@@ -40,6 +56,3 @@
4056
__description__ = 'Reinforcement Learning and Deep Learning Library for Researcher and Engineer.'
4157
__license__ = 'apache'
4258
__keywords__ = 'deep learning, machine learning, computer vision, nlp, supervised learning, unsupervised learning, reinforcement learning, tensorflow'
43-
44-
global_flag = {}
45-
global_dict = {}

0 commit comments

Comments
 (0)