setup.py - python 3.9 support

- move requirements files to dedicated folder
    - update all references to requirements files locations
    - setup.py: remove git requirements references
    - setup.py: allow running in python 3.9
    - windows/linux installers: default to python 3.9 environment
    - faceswap.py: cleaner python version check
This commit is contained in:
torzdf
2022-05-16 11:28:09 +01:00
parent e0d9c6e7ee
commit 17d35ea423
13 changed files with 31 additions and 34 deletions

6
.gitignore vendored
View File

@@ -3,10 +3,14 @@
!*.keep
!*.md
# Requirements files
!/requirements/
!/requirements/*requirements*.txt
!/requirements/*conda*.yml
# Root files
!Dockerfile*
!.pylintrc
!*requirements*.txt
!setup.cfg
!.travis.yml
!/faceswap.py

View File

@@ -12,6 +12,7 @@ DIR_CONDA="$HOME/miniconda3"
CONDA_EXECUTABLE="${DIR_CONDA}/bin/conda"
CONDA_TO_PATH=false
ENV_NAME="faceswap"
PYENV_VERSION="3.9"
DIR_FACESWAP="$HOME/faceswap"
VERSION="nvidia"
@@ -348,7 +349,7 @@ create_env() {
# Create Python 3.8 env for faceswap
delete_env
info "Creating Conda Virtual Environment..."
yellow ; "$CONDA_EXECUTABLE" create -n "$ENV_NAME" -q python=3.8 -y
yellow ; "$CONDA_EXECUTABLE" create -n "$ENV_NAME" -q python="$PYENV_VERSION" -y
}

View File

@@ -22,7 +22,7 @@ InstallDir $PROFILE\faceswap
# Install cli flags
!define flagsConda "/S /RegisterPython=0 /AddToPath=0 /D=$PROFILE\MiniConda3"
!define flagsRepo "--depth 1 --no-single-branch ${wwwRepo}"
!define flagsEnv "-y python=3.8"
!define flagsEnv "-y python=3.9"
# Folders
Var ProgramData

View File

@@ -11,7 +11,7 @@ RUN apt-get update -qq -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY _requirements_base.txt /opt/
COPY ./requirements/_requirements_base.txt /opt/
RUN pip3 install --upgrade pip
RUN pip3 --no-cache-dir install -r /opt/_requirements_base.txt && rm /opt/_requirements_base.txt

View File

@@ -15,8 +15,8 @@ RUN rm get-pip.py
# install requirements
RUN apt-get install ffmpeg git -y
COPY _requirements_base.txt /opt/
COPY requirements_nvidia.txt /opt/
COPY ./requirements/_requirements_base.txt /opt/
COPY ./requirements/requirements_nvidia.txt /opt/
RUN python3.8 -m pip --no-cache-dir install -r /opt/requirements_nvidia.txt && rm /opt/_requirements_base.txt && rm /opt/requirements_nvidia.txt
RUN python3.8 -m pip install jupyter matplotlib

View File

@@ -120,9 +120,9 @@ Do not follow these steps if the Easy Install above completed succesfully.
If you are using an Nvidia card make sure you have the correct versions of Cuda/cuDNN installed for the required version of Tensorflow
- Install tkinter (required for the GUI) by typing: `conda install tk`
- Install requirements:
- For Nvidia GPU users: `pip install -r requirements_nvidia.txt`
- For AMD GPU users: `pip install -r requirements_amd.txt`
- For CPU users: `pip install -r requirements_cpu.txt`
- For Nvidia GPU users: `pip install -r ./requirements/requirements_nvidia.txt`
- For AMD GPU users: `pip install -r ./requirements/requirements_amd.txt`
- For CPU users: `pip install -r ./requirements/requirements_cpu.txt`
## Running faceswap
- If you are not already in your virtual environment follow [these steps](#entering-your-virtual-environment)
@@ -176,7 +176,7 @@ $ source ~/miniforge3/bin/activate
#### Easy install
```sh
$ conda deactivate
$ conda env create -f conda-environment-apple-silicon.yml
$ conda env create -f ./requirements/conda-environment-apple-silicon.yml
$ conda activate faceswap
```
- Enter the command `python faceswap.py gui` and follow the prompts:
@@ -219,7 +219,7 @@ Enter your virtual environment and then enter the folder that faceswap has been
```bash
python setup.py
```
If setup fails for any reason you can still manually install the packages listed within requirements.txt
If setup fails for any reason you can still manually install the packages listed within the files in the requirements folder.
### About some of the options
- CUDA: For acceleration. Requires a good nVidia Graphics Card (which supports CUDA inside)

View File

@@ -12,9 +12,7 @@ _LANG = gettext.translation("faceswap", localedir="locales", fallback=True)
_ = _LANG.gettext
if sys.version_info[0] < 3:
raise Exception("This program requires at least python3.7")
if sys.version_info[0] == 3 and sys.version_info[1] < 7:
if sys.version_info < (3, 7):
raise Exception("This program requires at least python3.7")

View File

@@ -126,23 +126,16 @@ class Environment():
req_files = ["_requirements_base.txt", f"requirements_{suffix}"]
pypath = os.path.dirname(os.path.realpath(__file__))
requirements = []
git_requirements = []
for req_file in req_files:
requirements_file = os.path.join(pypath, req_file)
requirements_file = os.path.join(pypath, "requirements", req_file)
with open(requirements_file, encoding="utf8") as req:
for package in req.readlines():
package = package.strip()
# parse_requirements can't handle git dependencies, so extract and then
# manually add to final list
if package and package.startswith("git+"):
git_requirements.append((package, []))
continue
if package and (not package.startswith(("#", "-r"))):
requirements.append(package)
self.required_packages = [(pkg.name, pkg.specs)
for pkg in parse_requirements(requirements)
if pkg.marker is None or pkg.marker.evaluate()]
self.required_packages.extend(git_requirements)
def check_permission(self):
""" Check for Admin permissions """
@@ -166,10 +159,12 @@ class Environment():
def check_python(self):
""" Check python and virtual environment status """
self.output.info(f"Installed Python: {self.py_version[0]} {self.py_version[1]}")
if not (self.py_version[0].split(".")[0] == "3"
and self.py_version[0].split(".")[1] in ("7", "8")
and self.py_version[1] == "64bit") and not self.updater:
self.output.error("Please run this script with Python version 3.7 or 3.8 "
if self.updater:
return
if not ((3, 7) <= sys.version_info < (3, 10) and self.py_version[1] == "64bit"):
self.output.error("Please run this script with Python version 3.7 to 3.9 "
"64bit and try again.")
sys.exit(1)
@@ -209,7 +204,7 @@ class Environment():
def get_installed_packages(self):
""" Get currently installed packages """
installed_packages = {}
with Popen(f"\"{sys.executable}\" -m pip freeze", shell=True, stdout=PIPE) as chk:
with Popen(f"\"{sys.executable}\" -m pip freeze --local", shell=True, stdout=PIPE) as chk:
installed = chk.communicate()[0].decode(self.encoding).splitlines()
for pkg in installed:
@@ -663,18 +658,17 @@ class Install():
def check_missing_dep(self):
""" Check for missing dependencies """
for key, specs in self.env.required_packages:
if self.env.is_conda:
# Get Conda alias for Key
if self.env.is_conda: # Get Conda alias for Key
key = CONDA_MAPPING.get(key, (key, None))[0]
if (key == "git+https://github.com/deepfakes/nvidia-ml-py3.git" and
self.env.installed_packages.get("nvidia-ml-py3", "") == "7.352.1"):
# Annoying explicit hack to get around our custom version of nvidia-ml=py3 being
# constantly re-downloaded
continue
if key not in self.env.installed_packages:
# Add not installed packages to missing packages list
self.env.missing_packages.append((key, specs))
continue
installed_vers = self.env.installed_packages.get(key, "")
if specs and not all(self._operators[spec[0]](installed_vers, spec[1])
for spec in specs):
self.env.missing_packages.append((key, specs))