'activate venv with pyenv

I followed this guide to install pyenv in order to manage all python versions I have installed on my Mac. However, it is not clear to me what the pyenv global 3.7.3 command does and how I can activate a venv that uses python 3.7. If I type:

$ pyenv version
3.7.3

But apparently this is not enough to activate the venv?



Solution 1:[1]

list python versions in terminal:

$ pyenv install --list | grep " 3\.[678]"

Install Python version if not in list:

$ pyenv install 3.8.6

Create virtual env with python version:

$ pyenv virtualenv 3.8.6 project1

List versions of virtual environments:

$ pyenv versions

Activate a virtual version:

pyenv activate project1

Solution 2:[2]

pyenv global 3.7.3

sets the global version of Python to 3.7.3. It means that if you decide to use Python on your machine without using a virtual environment, then the version 3.7.3 is going to be used as a default.

2) In order to activate the virtual environment use

pyenv activate <name>

and to deactivate the virtual environment use

pyenv deactivate

For more details check this link https://github.com/pyenv/pyenv-virtualenv

Solution 3:[3]

If you're using virtualenv, just type

pyenv virtualenvs

Then to activate a particular env

pyenv activate [name]

Solution 4:[4]

So, in theory, the simple way of doing it is to get all permutations like so.

from itertools import product
from string import ascii_uppercase, digits

ups = ascii_uppercase
lows = ascii_lowercase

for x in product(ups, digits, ups, digits, ups, ups, digits, lows):
    print("".join(x))

However, in practice you will most likely run out of memory. Please be aware that there is a LOT of permutations (11881376000 to be exact), so you will most likely want to get a subset of them. You could that this way, where n is the the number of permutations you want.

def alphastring_generator(pattern, n):

    for idx, x in enumerate(product(*pattern)):
        if idx > n:
             break
        yield "".join(x)

my_pattern = [ups, digits, ups, digits, ups, ups, digits, lows]

result = [*alphastring_generator(my_pattern, n=1000)]

Solution 5:[5]

You can use random.sample and select k=8 pieces from the list you want.

To meet your requirements, you can generate the characters in the individual categories (uppercase, lowercase, digits) without repetition, and reorder them like. You can put it into a loop, and write the result into a file.

import random
import string

random.seed(0)
NUM_WORDS = 10
with open("wordlist.txt","w",encoding="utf-8") as ofile:
    for _ in range(NUM_WORDS):
        uppc = random.sample(string.ascii_uppercase,k=4)
        lowc = random.sample(string.ascii_lowercase,k=1)
        digi = random.sample(string.digits,k=3)
        word = uppc[0] + digi[0] + uppc[1] + digi[1] + uppc[2] + uppc[3] + digi[2] + lowc[0]
        print(word,file=ofile)

Is this what you want? Or did you mean something else by without repetition?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel
Solution 2 alv2017
Solution 3 Chase Denecke
Solution 4
Solution 5