Python Forum
ImportError: cannot import name 'Pyfhel' from 'Pyfhel'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ImportError: cannot import name 'Pyfhel' from 'Pyfhel'
#1
I use some recently GitHub publish code ----->https://github.com/ibarrond/Pyfhel it return me error
Error:
ImportError: cannot import name 'Pyfhel' from 'Pyfhel'

Where Pyfhel i have installed from git command line and as well from terminal shown in the GitHub code readme file and PyPtxt mean plaintext and PyCtxt ciphertext.
How to solve this error if i just write from Pyfhel import* instead of from Pyfhel import Pyfhel, PyPtxt, PyCtxt still it give me an error.
import time

from Pyfhel import Pyfhel, PyPtxt, PyCtxt
# Pyfhel class contains most of the functions.
# PyPtxt is the plaintext class
# PyCtxt is the ciphertext class


print("==============================================================")
print("================== Pyfhel CONTEXT PARAMETERS =================")
print("==============================================================")


print("1. p (long): Plaintext modulus. All operations are modulo p. ")
HE = Pyfhel()           # Creating empty Pyfhel object
HE.contextGen(p=65537)  # Generating context. The value of p is important.
                        #  There are many configurable parameters on this step
HE.keyGen()             # Key Generation.


print("2. m (long=2048): Polynomial coefficient modulus.")
print("   Higher allows more encrypted operations. In batch mode it is the number of integers per ciphertext.")

def time_demo_helloworld(integer1=127, integer2=-2):
    start = time.time()
    ctxt1 = HE.encryptInt(integer1) # Encryption makes use of the public key
    ctxt2 = HE.encryptInt(integer2) # For integers, encryptInt function is used.
    ctxtSum = ctxt1 + ctxt2         # `ctxt1 += ctxt2` for quicker inplace operation
    ctxtSub = ctxt1 - ctxt2         # `ctxt1 -= ctxt2` for quicker inplace operation
    ctxtMul = ctxt1 * ctxt2         # `ctxt1 *= ctxt2` for quicker inplace operation
    resSum = HE.decryptInt(ctxtSum)
    resSub = HE.decryptInt(ctxtSub) 
    resMul = HE.decryptInt(ctxtMul)
    end = time.time()
    print(f"Elapsed time: {end - start}")
    results = (resSum==125, resSub==129, resMul==-254)
    return end - start, results
Error:
Error:
Traceback (most recent call last): File "D:/Clustering/Pyfhel-master/Pyfhel-master/examples/Demo_ContextParameters.py", line 12, in <module> from Pyfhel import Pyfhel, PyPtxt, PyCtxt ImportError: cannot import name 'Pyfhel' from 'Pyfhel' (D:\Clustering\Pyfhel-master\Pyfhel-master\Pyfhel\__init__.py)
Process finished with exit code 1
Reply
#2
install instructions from PyPi (on command line, not 'git command line'), page: pip install Pyfhel
Reply
#3
@Larz60+ i follow the sample procedure to install Pyfhel https://pypi.org/project/Pyfhel/ and install it where still it give me the same error
PyPl installation i have done the follow command by using Linux
1) git clone --recursive https://github.com/ibarrond/Pyfhel.git
2) pip install
Reply
#4
To use the method that you are showing, and after the clone, the pip command has to be pip install .
you need the ' .' after 'pip install'

the method I show is to go to the command line, and then type verbatim: pip install Pyfhel
Reply
#5
install it using pip/pip3
Reply
#6
Install done accordingly PyPl but still the same import error for all demo
1) git clone --recursive https://github.com/ibarrond/Pyfhel.git
2) pip install .
3) pip install Pyphel
here is share my installing link screen shot of Linux have a look--------> https://ibb.co/FWj60mN
Reply
#7
You get a error message normal site-packages is not writeable
This can be a permission problem or Python/pip problem.
If you do pip -V and python3 -V dos both point to Python 3.8?
Try install with python3 -m pip install Pyfhel

If type python3 terminal dos python 3.8 start? it look like it install ok to 3.8.
Then test with from Pyfhel import Pyfhel, PyPtxt, PyCtxt

I know you struggle with this basic command line stuff as shown in you last post.
Here a run with virtual environment(build into Python) which is the best way to try if struggle or use in general.
# Make
tom@tom-VirtualBox:~$ python -m venv pyhel_env
# cd in
tom@tom-VirtualBox:~$ cd pyhel_env/
# Activate
tom@tom-VirtualBox:~/pyhel_env$ source bin/activate
# Test python
(pyhel_env) tom@tom-VirtualBox:~/pyhel_env$ python -V
Python 3.9.6
# Test pip,see it point this folder
(pyhel_env) tom@tom-VirtualBox:~/pyhel_env$ pip -V
pip 21.1.3 from /home/tom/pyhel_env/lib/python3.9/site-packages/pip (python 3.9)

# Install
(pyhel_env) tom@tom-VirtualBox:~/pyhel_env$ pip install Pyfhel
Collecting Pyfhel
  Downloading Pyfhel-2.3.1.tar.gz (716 kB)
..... 
Successfully installed Pyfhel-2.3.1 cython-0.29.24 numpy-1.21.2

# Test that is work
(pyhel_env) tom@tom-VirtualBox:~/pyhel_env$ python 
Python 3.9.6 (default, Aug  3 2021, 16:49:17) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from Pyfhel import Pyfhel, PyPtxt, PyCtxt
>>> 
>>> Pyfhel
<class 'Pyfhel.Pyfhel.Pyfhel'>
>>> exit()
Reply
#8
100% right what you suggest but have look ----> https://ibb.co/8dwTHh1 installation is done but still return the same error.
Reply
#9
You most type python3 not python.
Then you test import.
from Pyfhel import Pyfhel, PyPtxt, PyCtxt
Reply
#10
The Error has been solved @snippsat and Larz60+ many thanks brothers.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Cannot import easysnmp: ImportError: libnetsnmp.so.30 Calab 4 999 Jun-08-2023, 08:52 PM
Last Post: Gribouillis
  ImportError: cannot import name 'get_config' russray2008 0 4,678 Sep-20-2021, 02:18 PM
Last Post: russray2008
  ImportError: cannot import name 'Union' from '_ctypes' (unknown location) ciuffoly 15 10,260 Oct-09-2020, 06:58 AM
Last Post: ciuffoly
  ImportError: cannot import name 'Request' from 'request' abhishek81py 1 3,859 Jun-18-2020, 08:07 AM
Last Post: buran
  ImportError: cannot import name 'MidiEvaluator' from 'parser' (Windows 10) spiffspaceman 4 2,630 May-22-2020, 10:16 PM
Last Post: snippsat
  ImportError: cannot import name 'X ' from ' Y' (Unknown location) Arjunpi 1 4,318 Apr-30-2020, 12:56 AM
Last Post: Larz60+
  problem with mapnik in anaconda python 2: from _mapnik import * ImportError: DLL load parsley 0 1,873 Dec-11-2019, 07:50 AM
Last Post: parsley
  getting ImportError: cannot import name 'HAProxyServer' deepakkr3110 0 1,619 Nov-12-2019, 07:48 AM
Last Post: deepakkr3110
  ImportError: cannot import name 'gui' from 'appJar' CabbageMan 1 2,793 Sep-04-2019, 07:31 PM
Last Post: Gribouillis
  ImportError: cannot import name 'path' user123 2 12,375 Jul-14-2019, 10:08 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020