python - Docker与Django一起编写: 'ascii'编解码器无法解码位置7的字节0xcd:序数不在范围内(128)

标签 python django docker docker-compose

我只是从Docker和Django开始。我尝试在此处创建示例Django产品:https://docs.docker.com/compose/django

我制作了Dockerfile,Requirements.txt和docker-compose.yml。但是当我尝试使用docker-compose命令创建Django项目时,出现错误:

docker-compose run web django-admin.py startproject MyProject .
Traceback (most recent call last):
File "docker-compose", line 3, in <module>
File "compose\cli\main.py", line 64, in main
File "compose\cli\main.py", line 116, in perform_command
File "compose\cli\main.py", line 712, in run
File "compose\cli\main.py", line 1020, in run_one_off_container
File "compose\cli\main.py", line 1100, in call_docker
File "distutils\spawn.py", line 220, in find_executable
File "ntpath.py", line 85, in join
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcd in position 7: 
ordinal not in range(128)
Failed to execute script docker-compose

我尝试搜索相同的问题,但没有帮助。

Windows 10 Pro(如果重要,英语不是系统语言)。

我的Docker:
docker --version
Docker version 17.03.1-ce, build c6d412e
docker-compose --version
docker-compose version 1.11.2, build f963d76f

Dockerfile:
FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/

requirements.txt:
Django
psycopg2

docker-compose.yml:
version: '2'
services:
db:
 image: postgres
web:
 build: .
 command: python manage.py runserver 0.0.0.0:8000
 volumes:
   - .:/code
 ports:
   - "8000:8000"
 depends_on:
   - db

谢谢大家!

更新:ntpath.py,第85行的一部分,在联接中:
def join(path, *paths):
path = os.fspath(path)
if isinstance(path, bytes):
    sep = b'\\'
    seps = b'\\/'
    colon = b':'
else:
    sep = '\\'
    seps = '\\/'
    colon = ':'
try:
    if not paths:
        path[:0] + sep  #23780: Ensure compatible data type even if p is null.
    result_drive, result_path = splitdrive(path)
    for p in map(os.fspath, paths):
        p_drive, p_path = splitdrive(p)
        if p_path and p_path[0] in seps:
            # Second path is absolute
            if p_drive or not result_drive:
                result_drive = p_drive
            result_path = p_path
            continue
        elif p_drive and p_drive != result_drive:
            if p_drive.lower() != result_drive.lower():
                # Different drives => ignore the first path entirely
                result_drive = p_drive
                result_path = p_path
                continue
            # Same drive in different case
            result_drive = p_drive
        # Second path is relative to the first
        if result_path and result_path[-1] not in seps:
            result_path = result_path + sep
        result_path = result_path + p_path
    ## add separator between UNC and non-absolute path
    if (result_path and result_path[0] not in seps and
        result_drive and result_drive[-1:] != colon):
        return result_drive + sep + result_path
    return result_drive + result_path
except (TypeError, AttributeError, BytesWarning):
    genericpath._check_arg_types('join', path, *paths)
    raise

最佳答案

您应该在Dockerfile的顶部设置一个可识别UTF-8的语言环境

export LANG=C.UTF-8

关于python - Docker与Django一起编写: 'ascii'编解码器无法解码位置7的字节0xcd:序数不在范围内(128),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43408830/

相关文章:

Python 在二维网格上插入点值

python - 在 2 个列表中查找最接近的日期时间

python - 如何将 pandas DataFrame 的列解压为多个变量

php - nginx 不为 ingress-nginx 后面的 PHP 应用程序提供 JS、CSS 文件

python - Firebase存储上传文件-python

python - Django 用户表作为外键

django - 无法手动使用我的 DRF 序列化程序

python - 在 Django 中使用 Python Dropbox API

bash - 如何通过 docker run 将参数传递给 Shell 脚本

image - Docker - 从 docker repo 拉取失败 (EOF/403) 但从 RH repo 下载有效