大网数据广告活动
数据库与应用安全

mssql-conf setup fails with Python module error

· 52CE 我爱测

This article helps you resolve the mssql-conf setup fails with Python module error.

This article helps you to resolve an error that occurs when you try to run mssql-conf setup by using the Python module. This article also describes the Python requirements for Microsoft SQL Server on Linux, and provides a workaround if you're using an early Python version when you try to configure SQL Server on Linux.

Applies to: SQL Server 2019 on Linux

Symptoms

When you try to run mssql-conf setup after you install Microsoft SQL Server 2019, you receive a "module object has no attribute run" error message if you're using a Python version that's earlier than 3.5.

Consider the following scenarios:

testslesvm2:~ # /opt/mssql/bin/mssql-conf setup
Traceback (most recent call last):
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 17, in <module>
    import mssqlad
  File "/opt/mssql/lib/mssql-conf/mssqlad.py", line 15, in <module>
    import pyadutil
  File "/opt/mssql/lib/mssql-conf/pyadutil.py", line 6, in <module>
    import typing
ImportError: No module named 'typing'

You might also receive the following error message even after you fix the "typing" module dependency issue:

testslesvm2:~ # /opt/mssql/bin/mssql-conf setup
Warning: could not create log file for mssql-conf at /var/opt/mssql/log/mssql-conf/mssql-conf.log.
Traceback (most recent call last):
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 597, in <module>
    main()
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 593, in main
    processCommands()
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 310, in processCommands
    COMMAND_TABLE[args.which]()
  File "/opt/mssql/bin/../lib/mssql-conf/mssql-conf.py", line 93, in handleSetup
    mssqlconfhelper.setupSqlServer(eulaAccepted, noprompt=args.noprompt)
  File "/opt/mssql/lib/mssql-conf/mssqlconfhelper.py", line 964, in setupSqlServer
    if not checkInstall():
  File "/opt/mssql/lib/mssql-conf/mssqlconfhelper.py", line 934, in checkInstall
    return runScript(checkInstallScript, runAsRoot) == 0
  File "/opt/mssql/lib/mssql-conf/mssqlconfhelper.py", line 915, in runScript
    process = subprocess.run([pathToScript], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
AttributeError: 'module' object has no attribute 'run'

Note: The mssql-conf setup error can occur on systems on which the Microsoft SQL Server on Linux supported platform (RHEL, SLES, Ubuntu) includes Python 3 or another version that is earlier than 3.5. For more information about SQL Server on Linux-supported platforms, see Supported platform.

Cause

The error occurs because SQL Server 2019 and mssql-conf code rely on the Python 3.5+ functions.

Workaround

You have two options to work around this issue:

  • Upgrade Python 3 to 3.5 or a later version. Set the system so that when you run the /usr/bin/env python3 -V command, it points to Python 3.5 or 3.5+.

    Note: We have observed that some system functions that rely on Python versions that are earlier than 3.5 stop working after this upgrade. To avoid this problem, use the next option.

  • Create a symlink in your session that points Python 3 to Python 3.5 or 3.5+, and then run the mssql-conf commands to configure SQL Server. For more information, see the next section.

Create symlink (soft link) of Python 3

Follow these steps to create a session-specific symlink in which Python 3 points to Python 3.5 or a later version, and then run the mssql-conf setup.

  1. Install Python 3.5 or a later version. In this example, install Python 3.6:

    zypper in python36
    
  2. Install SQL Server.

    sudo zypper addrepo -fc https://packages.microsoft.com/config/sles/12/mssql-server-2019.repo
    sudo zypper --gpg-auto-import-keys refresh
    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    sudo zypper install -y mssql-server
    
  3. Switch to the root user, create the symlink in any folder, and then add the current path to $PATH. For example, the /usr/bin/env python3 -V symlink points to Python 3.6 instead of Python 3.4, as shown in the following code snippet:

    $sudo su
    testslesvm2:~ #:> sudo ln -s /usr/bin/python3.6 python3
    testslesvm2:~ # > PATH=$(pwd):$PATH
    testslesvm2:~ # ll
    total 4
    -rw------- 1 root root 982 Feb  9 20:03 .bash_history
    drwx------ 2 root root 111 Jan 26 08:50 .gnupg
    drwx------ 2 root root  29 Feb  9 19:27 .ssh
    drwxr-xr-x 2 root root   6 Jun 27  2017 bin
    lrwxrwxrwx 1 root root  18 Feb  9 19:47 python3 -> /usr/bin/python3.6
    testslesvm2:~ # /usr/bin/env python3 -V
    Python 3.6.15
    
  4. Run the mssql-conf setup or any other mssql-conf-based commands:

    /opt/mssql/bin/mssql-conf setup
    
  5. If you want to run the mssql-conf command in future to configure SQL Server, switch to the root user, and then run the PATH=$(pwd):$PATH command to add the current path to the $PATH environment variable. Then, run the mssql-conf command, as shown in step 4.

See also

Because Python 3.4 has already reached its EOL (end of life) status and will no longer receive security updates, we recommend that you use a supported, newer version of Python. For more information, see Python | endoflife.date.

Third-party contact disclaimer

Microsoft provides third-party contact information to help you find additional information about this topic. This contact information may change without notice. Microsoft does not guarantee the accuracy of third-party contact information.

Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors (upstream author metadata: ronking-zhu). Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 03/14/2022
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。