Python Forum
Trying to understand how import works in python
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to understand how import works in python
#1
I am using a python application which requires SimpleWebsocketServer..

I have done:

Quote:python3 -m pip install git+https://github.com/ecdsa/simple-websocket-server.git

Collecting git+https://github.com/ecdsa/simple-websocket-server.git
Cloning https://github.com/ecdsa/simple-websocket-server.git to /private/var/folders/3d/n3z5tt2n3fqc186ngh1ysmfr0000gn/T/pip-54tadi56-build
Installing collected packages: SimpleWebSocketServer
Running setup.py install for SimpleWebSocketServer ... done
Successfully installed SimpleWebSocketServer-0.1.0

But when I run the app, it fails from Import Error:
https://github.com/fyookball/electrum/bl...ets.py#L32

...

When I go into the python3 console, I can do:
Quote:Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import SimpleWebSocketServer
>>> SimpleWebSocketServer
<module 'SimpleWebSocketServer' from '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/SimpleWebSocketServer/__init__.py'>

So it looks like it is there.......... But if I try to do exactly what the app is doing, I have the same error:

Quote:>>> from SimpleWebSocketServer import WebSocket, SimpleSSLWebSocketServer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'WebSocket'

Can anyone help with what I am doing wrong?

Thanks!
Reply
#2
This is a example of how websocket work.
It's not the meaning that you should import,should run the server from command line.
λ python SimpleExampleServer.py --example echo
Now is the server running,open websocket.html.
There is a connect button.
Then send and get a response.
Output:
connected sent: hello world response: hello world
Reply
#3
Thanks but that's not at all related to the question I asked....
Reply
#4
Nevermind, I found that the problem was the code... Using the parent repo instead of the fork I was using resolved the issue.. this thread can be deleted.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  'import Path' do not understand how to use it tester_V 2 1,642 Jun-19-2021, 02:23 AM
Last Post: tester_V
  Python Regular expression, small sample works but not on file Acernz 5 2,933 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  Understand what it means that everything in Python is an object... bytecrunch 8 3,795 Mar-19-2021, 04:47 PM
Last Post: nilamo
  Understand order of magnitude performance gap between python and C++ ThelannOryat 4 2,706 Mar-17-2021, 03:39 PM
Last Post: ThelannOryat
  "Automate the Boring Stuff with Python" creating a path works but only for CMD promt Milos 2 2,868 Nov-28-2020, 01:08 PM
Last Post: Larz60+
  Works with Curl. Can't get it to work in Python bazcurtis 3 2,547 May-07-2020, 07:47 AM
Last Post: bazcurtis
  New to Python, How does this lambda expression works? Joshh_33 2 2,030 Mar-26-2020, 03:32 PM
Last Post: Joshh_33
  Trying to understand the python code spalisetty 2 1,869 Mar-16-2020, 08:11 AM
Last Post: javiertzr01
  time.sleep works erratically, a bug in Python? stipcevic 2 3,888 Jan-21-2020, 09:38 PM
Last Post: Marbelous
  I do not understand why my python looks different from tutorials. noodlespinbot 2 5,130 Oct-12-2019, 09:56 PM
Last Post: noodlespinbot

Forum Jump:

User Panel Messages

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