前提・実現したいこと
仮想環境上のPythonを2.xx から 3.xx へバージョンアップしたい。
ほかにいい方法がある、もしくは僕が試した方法の間違っている点などを教えていただきたいです。
発生している問題・エラーメッセージ
TASK [webserver : Python Framework] ****************************************************************************************************************************************** fatal: [server2]: FAILED! => {"changed": false, "msg": "Traceback (most recent call last):\n File \"/usr/bin/easy_install\", line 9, in <module>\n load_entry_point('setup tools==20.7.0', 'console_scripts', 'easy_install')()\n File \"/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py\", line 2293, in main\n distclass=Distri butionWithoutHelpCommands, **kw\n File \"/usr/lib/python2.7/distutils/core.py\", line 151, in setup\n dist.run_commands()\n File \"/usr/lib/python2.7/distutils/dist.py\" , line 953, in run_commands\n self.run_command(cmd)\n File \"/usr/lib/python2.7/distutils/dist.py\", line 972, in run_command\n cmd_obj.run()\n File \"/usr/lib/python 2.7/dist-packages/setuptools/command/easy_install.py\", line 414, in run\n self.easy_install(spec, not self.no_deps)\n File \"/usr/lib/python2.7/dist-packages/setuptools/ command/easy_install.py\", line 663, in easy_install\n return self.install_item(spec, dist.location, tmpdir, deps)\n File \"/usr/lib/python2.7/dist-packages/setuptools/co mmand/easy_install.py\", line 698, in install_item\n self.process_distribution(spec, dists[0], deps, \"Using\")\n File \"/usr/lib/python2.7/dist-packages/setuptools/comma nd/easy_install.py\", line 740, in process_distribution\n [requirement], self.local_index, self.easy_install\n File \"/usr/lib/python2.7/dist-packages/pkg_resources/__ini t__.py\", line 826, in resolve\n dist = best[req.key] = env.best_match(req, ws, installer)\n File \"/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py\", line 109 2, in best_match\n return self.obtain(req, installer)\n File \"/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py\", line 1104, in obtain\n return installer(re quirement)\n File \"/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py\", line 663, in easy_install\n return self.install_item(spec, dist.location, tmpdi r, deps)\n File \"/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py\", line 693, in install_item\n dists = self.install_eggs(spec, download, tmpdir)\n File \"/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py\", line 873, in install_eggs\n return self.build_and_install(setup_script, setup_base)\n File \ "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py\", line 1101, in build_and_install\n self.run_setup(setup_script, setup_base, args)\n File \"/usr/lib /python2.7/dist-packages/setuptools/command/easy_install.py\", line 1087, in run_setup\n run_setup(setup_script, args)\n File \"/usr/lib/python2.7/dist-packages/setuptool s/sandbox.py\", line 246, in run_setup\n raise\n File \"/usr/lib/python2.7/contextlib.py\", line 35, in __exit__\n self.gen.throw(type, value, traceback)\n File \"/us r/lib/python2.7/dist-packages/setuptools/sandbox.py\", line 195, in setup_context\n yield\n File \"/usr/lib/python2.7/contextlib.py\", line 35, in __exit__\n self.gen. throw(type, value, traceback)\n File \"/usr/lib/python2.7/dist-packages/setuptools/sandbox.py\", line 166, in save_modules\n saved_exc.resume()\n File \"/usr/lib/python2 .7/dist-packages/setuptools/sandbox.py\", line 141, in resume\n six.reraise(type, exc, self._tb)\n File \"/usr/lib/python2.7/dist-packages/setuptools/sandbox.py\", line 1 54, in save_modules\n yield saved\n File \"/usr/lib/python2.7/dist-packages/setuptools/sandbox.py\", line 195, in setup_context\n yield\n File \"/usr/lib/python2.7/di st-packages/setuptools/sandbox.py\", line 243, in run_setup\n DirectorySandbox(setup_dir).run(runner)\n File \"/usr/lib/python2.7/dist-packages/setuptools/sandbox.py\", l ine 273, in run\n return func()\n File \"/usr/lib/python2.7/dist-packages/setuptools/sandbox.py\", line 242, in runner\n _execfile(setup_script, ns)\n File \"/usr/lib /python2.7/dist-packages/setuptools/sandbox.py\", line 46, in _execfile\n exec(code, globals, locals)\n File \"/tmp/easy_install-0sKzHZ/Jinja2-3.0.0a1/setup.py\", line 6, in <module>\n File \"/usr/lib/python2.7/dist-packages/setuptools/sandbox.py\", line 403, in _open\n return _open(path,mode,*args,**kw)\nTypeError: 'encoding' is an inval id keyword argument for this function\n"}
該当のソースコード
vagrant@main:/srv/ops/ansible_project$ ansible-playbook -i inventories/hosts site.yml
試したこと
エラーメッセージを見る限り
ops\ansible_project\roles\webserver\tasks\install-app.yml
内の
yml
1- name: Python Framework 2 easy_install: 3 name: flask
でエラーが起きており、Pythonのバージョンが2.7であることが原因だと考えたので、python3.xxにバージョンアップできないか試しました。
具体的には、
\ops\fab_project\fabfile.py
内で
Python
1@task 2@roles('web') 3def deploy_web(): 4 run('apt-get install -y supervisor') 5 run('apt-get install -y gunicorn') 6 run('pip install Flask==1.1.0') 7 if not exists('root/work'): 8 run('mkdir /root/work') 9 10 put('roles/web/files/hello.py', 11 '/root/work/hello.py') 12 put('roles/web/files/app.conf', 13 '/etc/supervisor/conf.d/app.conf') 14 run('service supervisor restart') 15 16@task 17def deploy_dev_server(): 18 install_packages() 19 deploy_web() 20 print(green('success'))
ターミナルで
vagrant@main:/srv/ops/fab_project$ fab deploy_dev_server
実行結果
[root@172.16.200.101:22] out: The following additional packages will be installed: [root@172.16.200.101:22] out: libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-minimal python-pkg-resources python2.7 python2.7-minimal
ここでPython2.がインストールされている?なので
fabfile.py
deploy_web()
run('pip install python==3.7.6')
を追加して、再度上記コマンドを実行。しかしエラー?がでてしまいます。
実行結果
[root@172.16.200.101:22] run: pip install python==3.7.6 [root@172.16.200.101:22] out: DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A fu ture version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#p ython-2-support [root@172.16.200.101:22] out: ERROR: Could not find a version that satisfies the requirement python==3.7.6 (from versions: none) [root@172.16.200.101:22] out: ERROR: No matching distribution found for python==3.7.6
補足情報(FW/ツールのバージョンなど)
何がいるかが分からなかったため、フォルダ全体をGithubにアップロードしておきましたこちら
windows10
自分のPC上で動かしているPythonのバージョン
→3.7.4
仮想環境上のPythonのバージョン
→2.7.12
$ fab --version
→Fabric3 1.14.post1
Paramiko 2.7.1
$ ansible --version
→ ansible 2.4.2.0
python version = 3.5.2 (default, Oct 8 2019, 13:06:37) [GCC 5.4.0 20160609]
あなたの回答
tips
プレビュー