Home > Software engineering >  Can't install tensorflow in Docker on Silicon mac
Can't install tensorflow in Docker on Silicon mac

Time:05-04

I want to install tensorflow in Docker on M1 Mac.

I have this error when RUN pipenv lock

#13 3.637 CRITICAL:pipenv.patched.notpip._internal.resolution.resolvelib.factory:Could not find a version that satisfies the requirement tensorflow (from versions: none)

I simply set tensorflow='*' and python is 3.8, but it cant' find the tensorflow I just wonder,,, it is because on silicon mac?? or in my understanding docker file is independent from CPU, is it correct?

Dockerfile

FROM python:3.8
ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt-get install -y netcat

WORKDIR /usr/src/app

COPY .. .
COPY .env.local .env
COPY Pipfile.local Pipfile
RUN pip install --upgrade pip
RUN pip install pipenv
RUN pipenv lock
RUN pipenv install --system

RUN chmod  x entrypoint.local.sh

ENTRYPOINT ["./entrypoint.local.sh"]

Pipfile.local

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

tensorflow = "*"

[dev-packages]

[requires]
python_version = "3.8"

error log

#13 0.679 Creating a virtualenv for this project...                                                                                
#13 0.679 Pipfile: /usr/src/app/Pipfile                                                                                            
#13 0.689 Using /usr/local/bin/python3.8 (3.8.13) to create virtualenv...                                                          
⠴ Creating virtual environment...created virtual environment CPython3.8.13.final.0-64 in 366ms                                     
#13 1.128   creator CPython3Posix(dest=/root/.local/share/virtualenvs/app-lp47FrbD, clear=False, no_vcs_ignore=False, global=False)
#13 1.128   seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
#13 1.128     added seed packages: pip==22.0.4, setuptools==62.1.0, wheel==0.37.1
#13 1.128   activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
#13 1.128 
#13 1.188✔ Successfully created virtual environment! 
#13 1.497 Virtualenv location: /root/.local/share/virtualenvs/app-lp47FrbD
#13 1.512 Locking [dev-packages] dependencies...
#13 1.513 Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
⠙ Locking..✘ Locking Failed! 
#13 2.493 
#13 2.493 CRITICAL:pipenv.patched.notpip._internal.resolution.resolvelib.factory:Could not find a version that satisfies the requirement tensorflow (from versions: none)
#13 2.493 [ResolutionFailure]:   File "/usr/local/lib/python3.8/site-packages/pipenv/resolver.py", line 822, in _main
#13 2.493 [ResolutionFailure]:       resolve_packages(
#13 2.493 [ResolutionFailure]:   File "/usr/local/lib/python3.8/site-packages/pipenv/resolver.py", line 771, in resolve_packages
#13 2.493 [ResolutionFailure]:       results, resolver = resolve(
#13 2.493 [ResolutionFailure]:   File "/usr/local/lib/python3.8/site-packages/pipenv/resolver.py", line 751, in resolve
#13 2.493 [ResolutionFailure]:       return resolve_deps(
#13 2.493 [ResolutionFailure]:   File "/usr/local/lib/python3.8/site-packages/pipenv/utils/resolver.py", line 1068, in resolve_deps
#13 2.493 [ResolutionFailure]:       results, hashes, markers_lookup, resolver, skipped = actually_resolve_deps(
#13 2.493 [ResolutionFailure]:   File "/usr/local/lib/python3.8/site-packages/pipenv/utils/resolver.py", line 862, in actually_resolve_deps
#13 2.493 [ResolutionFailure]:       resolver.resolve()
#13 2.493 [ResolutionFailure]:   File "/usr/local/lib/python3.8/site-packages/pipenv/utils/resolver.py", line 663, in resolve
#13 2.493 [ResolutionFailure]:       raise ResolutionFailure(message=str(e))
#13 2.493 [pipenv.exceptions.ResolutionFailure]: Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
#13 2.493   You can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
#13 2.493   Hint: try $ pipenv lock --pre if it is a pre-release dependency.
#13 2.493 ERROR: No matching distribution found for tensorflow
#13 2.493 

CodePudding user response:

I reproduced your issue and was able to build the image using an explicit URL for a generic image: RUN pipenv install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.9.0-py3-none-any.whl and removing tensorflow from the Pipfile. This is a pipenv issue and not related to your CPU arch, AFAIU.

CodePudding user response:

Try setting your platform in your Dockerfile

FROM --platform=linux/arm64 python:3.8
...
  • Related