Edit: I've worked out that using include cs50 functionality or other modules (such as the ones used by serve.py) only work in the workspace folder and DO NOT work in other folders - see below for original problem.

Comments very much appreciated,


Hi I have a significant problem with the Python module in the cs50 IDE. I think it's caused by the cs50 functions such as cs50.get_char

I have a simple program called string.py:

s = input("name: ")
print("hello, {}".format(s))

It works exactly as expected.

Another small program, int.py:

import cs50

i = cs50.get_int()

Now, when I run int.py the IDE actually executes string.py.

I type in "python int.py"

~/workspace/python/ $ python int.py

I am prompted with the prompt from string.py

~/workspace/python/ $ python int.py


Then I get this long error message in the terminal. Full output:

~/workspace/python/ $ python int.py name: 55 hello, 55 Traceback (most recent call last): File "int.py", line 1, in import cs50 File "/usr/lib/python3/dist-packages/cs50/init.py", line 2, in from .sql import * File "/usr/lib/python3/dist-packages/cs50/sql.py", line 1, in import sqlalchemy File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/init.py", line 9, in from .sql import ( File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/init.py", line 98, in go(locals()) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/__init.py", line 96, in go from . import naming File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/naming.py", line 15, in from .. import event, events File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/events.py", line 11, in from .pool import Pool File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/pool.py", line 24, in from . import exc, log, event, interfaces, util File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/log.py", line 21, in import logging File "/usr/lib/python3.4/logging/__init.py", line 28, in from string import Template ImportError: cannot import name 'Template'

  • Not sure if it does matter here, but do not name your files the same as standard functions (like int) or modules (like string). Especially in dynamic languages, this can cause all kinds of behaviour! The more dynamic, the weirder, and Python is pretty dynamic. – Blauelf Jan 23 '17 at 10:24
  • Thanks for the reply, that's not it though: I'm replicating the prof's work in the lecture. I'm (almost) certain it's an issue with the cs50 module in the IDE. Either way, what you suggest is certainly good practice - ty. – Tikhon Jan 23 '17 at 11:42
  • Are you on the current software version (use update50)? And does renaming the files have any effect? I still don't get how the code from string.py gets called if not through some code trying to use module string, and accidentally accessing the file in the current directory instead. – Blauelf Jan 23 '17 at 12:13
  • Yes I did update, no renaming doesn't help. This has to be something to do with the module implementation... I have recently downloaded serve.py from the lecture. Mysteriously, the same thing happens again! – Tikhon Jan 24 '17 at 6:26
  • I am having the exact same issue. – Rushil Grover Feb 13 '17 at 19:35

I had the same problem as you describe in your post. As @Rushil mentioned in his comment, it can be sorted by renaming the file you have named "string.py" in your directory. Seems there is a conflict while importing the cs50 library and at the same time having a file called "string.py" in your folder...

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .