Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyenv_global does not set the correct version #221

Closed
hongbo-miao opened this issue Aug 4, 2023 · 4 comments
Closed

pyenv_global does not set the correct version #221

hongbo-miao opened this issue Aug 4, 2023 · 4 comments

Comments

@hongbo-miao
Copy link

hongbo-miao commented Aug 4, 2023

I am trying to set default global Python version. Here is my code:

- name: Install packages
  hosts: hm-ubuntu
  roles:
    - role: staticdev.pyenv
      pyenv_version: v2.3.23
      pyenv_env: user
      pyenv_python_versions:
        - 3.11.4
      pyenv_global:
        - 3.11.4

However, after I apply it on a Ubuntu machine, pyenv_global seems not being set up correctly.

Here is the result when running inside this Ubuntu machine. I am hoping it select 3.11.4 by default. However, the default version is still using system.

$ which pyenv
/home/parallels/pyenv/bin/pyenv

$ pyenv versions
* system (set by /home/parallels/pyenv/version)
  3.11.4

$ cat ~/pyenv/version
cat: /home/parallels/pyenv/version: No such file or directory

Any ideas? Thanks! 😃

@alexjung
Copy link

alexjung commented Aug 4, 2023

I encountered the same issue. Running pyenv global 3.X.X manually set the version correctly.

@hongbo-miao
Copy link
Author

When I use pyenv global 3.11.4 like below:

- name: Install pyenv
  hosts: hm-ubuntu
  roles:
    - role: staticdev.pyenv
      # https://github.com/pyenv/pyenv/releases
      pyenv_version: v2.3.23
      pyenv_env: user
      pyenv_python_versions:
        - 3.11.4
      pyenv_global:
        - 3.11.4
  tasks:
    - name: Set global Python version
      ansible.builtin.shell:
        cmd: pyenv global 3.11.4

I got error

fatal: [hm-ubuntu]: FAILED! => {"changed": true, "cmd": "pyenv global 3.11.4", "delta": "0:00:00.002468", "end": "2023-08-09 14:02:59.015918", "msg": "non-zero return code", "rc": 127, "start": "2023-08-09 14:02:59.013450", "stderr": "/bin/sh: 1: pyenv: not found", "stderr_lines": ["/bin/sh: 1: pyenv: not found"], "stdout": "", "stdout_lines": []}

I guess I will have to activate pyenv related environemnt.

Just share my other working workaround way ☺️

- name: Install pyenv
  hosts: hm-ubuntu
  roles:
    - role: staticdev.pyenv
      # https://github.com/pyenv/pyenv/releases
      pyenv_version: v2.3.23
      pyenv_env: user
      pyenv_python_versions:
        - 3.11.4
      pyenv_global:
        - 3.11.4
  tasks:
    - name: Creates directory ~/pyenv
      ansible.builtin.file:
        path: ~/pyenv
        state: directory
    - name: Set global Python version
      ansible.builtin.copy:
        dest: ~/pyenv/version
        content: 3.11.4
        mode: 0644

@hongbo-miao
Copy link
Author

Hmm this maybe fixed by #222 once it merged.

@staticdev
Copy link
Owner

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants