Ubuntu 12.04如何在终端中运行Python 3.3.2程序

时间:2021-03-20 17:30:30

OK so for school I am having to set up a computer using Ubuntu 12.04 to run Python programs written in Python 3.3. I was aware that 12.04 came with Python 3.2, so I followed the procedure in the first reply in this thread to install Python 3.3:

好的,所以对于学校我不得不使用Ubuntu 12.04设置一台计算机来运行用Python 3.3编写的Python程序。我知道12.04附带了Python 3.2,所以我按照这个线程的第一个回复中的步骤来安装Python 3.3:

Now when I open the Terminal, I type ~/bin/py to get it to display the following at the top of the terminal:

现在当我打开终端时,我输入〜/ bin / py来让它在终端顶部显示以下内容:

Python 3.3.2 (default, Dec 10 2013, 11:35:01)
[GCC 4.6.3] on Linux
Type "help", "copyright", "credits", or "license" for more information.
>>>

So far so good. Now I am having trouble replicating the functionality of the same Python program that I execute as follows on my Windows laptop.

到现在为止还挺好。现在我无法复制我在Windows笔记本电脑上执行的相同Python程序的功能。

(This is what I type in the Python commandline on windows)

(这是我在Windows上的Python命令行中键入的内容)

import filereader 
from filereader import * 
reader = filereader("C:\Python33\ab1copy.ab1") 
reader.show_entries()

The end result is a directory of data types found in the file. The filereader class is located in Python33\Lib\site-packages\filereader.py in the above example. On the Ubuntu computer its location is Python-3.3.2\Lib\site-packages\filereader.py. Also on Ubuntu, the ab1copy.ab1 file is located in the home directory for now.

最终结果是在文件中找到的数据类型的目录。 filereader类位于上例中的Python33 \ Lib \ site-packages \ filereader.py中。在Ubuntu计算机上,它的位置是Python-3.3.2 \ Lib \ site-packages \ filereader.py。同样在Ubuntu上,ab1copy.ab1文件现在位于主目录中。

After I achieve the recognition of Python 3.3.2 in the Ubuntu Terminal as noted above, how can I replicate my program's functionality there? If I try to put in the same first command "import filereader" I get the following error:

在我如上所述在Ubuntu终端中实现Python 3.3.2的识别之后,如何在那里复制程序的功能?如果我尝试输入相同的第一个命令“import filereader”,我会收到以下错误:

>>>import filereader
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'filereader'

2 个解决方案

#1


1  

try this in the terminal

在终端试试这个

python3 your_file.py

#2


0  

It's probably not in your python path.

它可能不在您的python路径中。

Check this to see where it looks for your source:

选中此项以查看其来源的来源:

import sys
print(sys.path)

#1


1  

try this in the terminal

在终端试试这个

python3 your_file.py

#2


0  

It's probably not in your python path.

它可能不在您的python路径中。

Check this to see where it looks for your source:

选中此项以查看其来源的来源:

import sys
print(sys.path)