user121214: Hello everyone when I start this code on PYCHARM looks like no
problem. But when I turned this code from python to exe and exe
don't start and it says: import  error: cannot import name
"privtopub" from 'bitcoin'
import random

import requests

import base58

import hashlib

from bitcoin import privtopub, pubtoaddr

# Some code here

while True:

    i += 1

    first_character = "89ABCDEF"
    first_character.encode('utf-8')
    last_15_character = "0123456789ABCDEF"
    last_15_character.encode('utf-8')
    privateKeyByte = ("000000000000000000000000000000000000000000000000" + "".join(
        random.choice(first_character) for _ in range(1)) + "".join(
        random.choice(last_15_character) for _ in range(15))).encode('utf-8')
    privateKey = str(privateKeyByte)[2:-1]
    extendedPrivateKey = ("80" + privateKey)
    extendedPrivateKeyByte = bytearray.fromhex(extendedPrivateKey)
    firstHash = hashlib.sha256()
    firstHash.update(extendedPrivateKeyByte)
    secondHash = hashlib.sha256()
    firstHashFromHex = bytearray.fromhex(firstHash.hexdigest())
    secondHash.update(firstHashFromHex)
    checksum = secondHash.hexdigest()[0:8]
    finalPrivateKey = extendedPrivateKey + checksum
    encodedKey = bytes.fromhex(finalPrivateKey)
    wifKey = base58.b58encode(encodedKey)
    wifKeyString = str(wifKey)[2:-1]
    publicKey = privtopub(privateKey)
    btcAddress = pubtoaddr(publicKey)


Last 2 code i mean
publicKey = privtopub(privateKey) and btcAddress = pubtoaddr(publicKey) cannot import from bitcoin ? why ?

Also i had another problem but i solved it turned my privateKeyByte
to byte add this code " .encode('utf-8')." end of the privateKeyByte

When i delete this all code and to get to public adress with
this way :


    import random
    import bitcoin
    import requests
    
    while True:
        i += 1
        liste_ilk_basamak = ("89ABCDEF")
        liste_son15_basamak = ("0123456789ABCDEF")
        private_key_random = "".join(random.choice(liste_ilk_basamak) for _ in range(1)) + "".join(
            random.choice(liste_son15_basamak) for _ in range(15))
        decoded_private_key = bitcoin.decode_privkey(private_key_random, 'hex')
        valid_private_key = 0 < decoded_private_key < bitcoin.N
        wif_encoded_private_key = bitcoin.encode_privkey(decoded_private_key, 'wif')
        public_key = bitcoin.fast_multiply(bitcoin.G, decoded_private_key)
        adress = bitcoin.pubkey_to_address(public_key)


İ Have This Error : AttributeError: Module "bitcoin" has no attribute 'decode_privkey'

I am trying to solve this problem 4 days and I am going to be crazy lost my mind :S help me pls :)

user111667: I solved the problem by installing the bitcoin package again.
I was getting this error message with my script doubleslow-base.py:
Traceback (most recent call last):
  File "./doubleslow-base.py", line 136, in <module>
    print_the_secrets(digest256_final)
  File "/home/valentin/python/doubleslow/doubleslow_module.py", line 301, in print_the_secrets
    my_256_bit_secret_WIF = bitcoin.encode_privkey(my_256_bit_secret_HEX,"wif_compressed")
AttributeError: module 'bitcoin' has no attribute 'encode_privkey'

After installing it again it works:
$ pip3 install --user bitcoin
Collecting bitcoin
Installing collected packages: bitcoin
Successfully installed bitcoin-1.1.42

Just in case I installed again all requirements:
$ pip3 install -r requirements.txt

I am not sure why this solved the problem. The script was working last year (when it was released) on the same system.
I was able to run your script with python2 and python3 by installing bitcoin with pip install --user bitcoin (to work with python2) and by defining i:
#!/usr/bin/python3

import random
import bitcoin
import requests

i=0

while True:
    i += 1
    liste_ilk_basamak = ("89ABCDEF")
    liste_son15_basamak = ("0123456789ABCDEF")
    private_key_random = "".join(random.choice(liste_ilk_basamak) for _ in range(1)) + "".join(
        random.choice(liste_son15_basamak) for _ in range(15))
    decoded_private_key = bitcoin.decode_privkey(private_key_random, 'hex')
    valid_private_key = 0 < decoded_private_key < bitcoin.N
    wif_encoded_private_key = bitcoin.encode_privkey(decoded_private_key, 'wif')
    public_key = bitcoin.fast_multiply(bitcoin.G, decoded_private_key)
    adress = bitcoin.pubkey_to_address(public_key)

    print(adress)

The module requests is not being used, so the line import requests can be removed. I added a print to see what happens and to confirm that the script is actually working.
First, I got this error:
$ python3 ./test0.py 
Traceback (most recent call last):
  File "./test0.py", line 9, in <module>
    i += 1
NameError: name 'i' is not defined

Obviously, you forgot to define i.

121214: <p>Hello everyone when I start this code on PYCHARM looks like no
problem. But when I turned this code from python to exe and exe
don't start and it says: import  error: cannot import name
&quot;privtopub&quot; from 'bitcoin'</p>
<pre><code>import random

import requests

import base58

import hashlib

from bitcoin import privtopub, pubtoaddr

# Some code here

while True:

    i += 1

    first_character = &quot;89ABCDEF&quot;
    first_character.encode('utf-8')
    last_15_character = &quot;0123456789ABCDEF&quot;
    last_15_character.encode('utf-8')
    privateKeyByte = (&quot;000000000000000000000000000000000000000000000000&quot; + &quot;&quot;.join(
        random.choice(first_character) for _ in range(1)) + &quot;&quot;.join(
        random.choice(last_15_character) for _ in range(15))).encode('utf-8')
    privateKey = str(privateKeyByte)[2:-1]
    extendedPrivateKey = (&quot;80&quot; + privateKey)
    extendedPrivateKeyByte = bytearray.fromhex(extendedPrivateKey)
    firstHash = hashlib.sha256()
    firstHash.update(extendedPrivateKeyByte)
    secondHash = hashlib.sha256()
    firstHashFromHex = bytearray.fromhex(firstHash.hexdigest())
    secondHash.update(firstHashFromHex)
    checksum = secondHash.hexdigest()[0:8]
    finalPrivateKey = extendedPrivateKey + checksum
    encodedKey = bytes.fromhex(finalPrivateKey)
    wifKey = base58.b58encode(encodedKey)
    wifKeyString = str(wifKey)[2:-1]
    publicKey = privtopub(privateKey)
    btcAddress = pubtoaddr(publicKey)
</code></pre>
<ul>
<li><p>Last 2 code i mean
<code>publicKey = privtopub(privateKey)</code> and <code>btcAddress = pubtoaddr(publicKey) cannot import from bitcoin</code> ? why ?</p>
</li>
<li><p>Also i had another problem but i solved it turned my privateKeyByte
to byte add this code &quot; .encode('utf-8').&quot; end of the privateKeyByte</p>
</li>
<li><p>When i delete this all code and to get to public adress with
this way :</p>
</li>
</ul>
<pre><code>    import random
    import bitcoin
    import requests
    
    while True:
        i += 1
        liste_ilk_basamak = (&quot;89ABCDEF&quot;)
        liste_son15_basamak = (&quot;0123456789ABCDEF&quot;)
        private_key_random = &quot;&quot;.join(random.choice(liste_ilk_basamak) for _ in range(1)) + &quot;&quot;.join(
            random.choice(liste_son15_basamak) for _ in range(15))
        decoded_private_key = bitcoin.decode_privkey(private_key_random, 'hex')
        valid_private_key = 0 &lt; decoded_private_key &lt; bitcoin.N
        wif_encoded_private_key = bitcoin.encode_privkey(decoded_private_key, 'wif')
        public_key = bitcoin.fast_multiply(bitcoin.G, decoded_private_key)
        adress = bitcoin.pubkey_to_address(public_key)
</code></pre>
<ul>
<li>İ Have This Error : AttributeError: Module &quot;bitcoin&quot; has no attribute 'decode_privkey'</li>
</ul>
<p>I am trying to solve this problem 4 days and I am going to be crazy lost my mind :S help me pls :)</p>
 111667: <p>I solved the problem by installing the <code>bitcoin</code> package again.</p>
<p>I was getting this error message with my script <a href="https://github.com/vstoykovbg/doubleslow" rel="nofollow noreferrer">doubleslow-base.py</a>:</p>
<pre><code>Traceback (most recent call last):
  File &quot;./doubleslow-base.py&quot;, line 136, in &lt;module&gt;
    print_the_secrets(digest256_final)
  File &quot;/home/valentin/python/doubleslow/doubleslow_module.py&quot;, line 301, in print_the_secrets
    my_256_bit_secret_WIF = bitcoin.encode_privkey(my_256_bit_secret_HEX,&quot;wif_compressed&quot;)
AttributeError: module 'bitcoin' has no attribute 'encode_privkey'
</code></pre>
<p>After installing it again it works:</p>
<pre><code>$ pip3 install --user bitcoin
Collecting bitcoin
Installing collected packages: bitcoin
Successfully installed bitcoin-1.1.42
</code></pre>
<p>Just in case I installed again all requirements:</p>
<pre><code>$ pip3 install -r requirements.txt
</code></pre>
<p>I am not sure why this solved the problem. The script was working last year (when it was released) on the same system.</p>
<p>I was able to run your script with python2 and python3 by installing <code>bitcoin</code> with <code>pip install --user bitcoin</code> (to work with python2) and by defining <code>i</code>:</p>
<pre><code>#!/usr/bin/python3

import random
import bitcoin
import requests

i=0

while True:
    i += 1
    liste_ilk_basamak = (&quot;89ABCDEF&quot;)
    liste_son15_basamak = (&quot;0123456789ABCDEF&quot;)
    private_key_random = &quot;&quot;.join(random.choice(liste_ilk_basamak) for _ in range(1)) + &quot;&quot;.join(
        random.choice(liste_son15_basamak) for _ in range(15))
    decoded_private_key = bitcoin.decode_privkey(private_key_random, 'hex')
    valid_private_key = 0 &lt; decoded_private_key &lt; bitcoin.N
    wif_encoded_private_key = bitcoin.encode_privkey(decoded_private_key, 'wif')
    public_key = bitcoin.fast_multiply(bitcoin.G, decoded_private_key)
    adress = bitcoin.pubkey_to_address(public_key)

    print(adress)
</code></pre>
<p>The module <code>requests</code> is not being used, so the line <code>import requests</code> can be removed. I added a <code>print</code> to see what happens and to confirm that the script is actually working.</p>
<p>First, I got this error:</p>
<pre><code>$ python3 ./test0.py 
Traceback (most recent call last):
  File &quot;./test0.py&quot;, line 9, in &lt;module&gt;
    i += 1
NameError: name 'i' is not defined
</code></pre>
<p>Obviously, you forgot to define <code>i</code>.</p>
