• TurtleWorld Python3 安装


    图书馆借了本书,一本好书《像计算机科学家一样思考Python》(Think Python
    TurtleWorld是作者 Allen B. Downey 写的一个包 swampy 里的一个模块,用来学习编程的。
    这个包没有支持 Python3 直接下载安装,只提供了源文件。需要下载了之后调用。

    其实官方网站有解释怎么安装,可是一下子就是看不懂。

    Swampy for Python 3 is not available as a package. But the source code is available in a zip file:
    Swampy source for Python 3: swampy-2.1.5.python3.zip
    The simplest way to use this code is to unzip it in your home directory, cd into the unzipped directory and work there. Or you can put it any place you like, then add the new directory to the Python search path.
    Either way, you should be able to import Swampy modules, but instead of specifying the package and module like this:
    from swampy.TurtleWorld import *
    You would just specify the module, like this:
    from TurtleWorld import *

    • 嗯,他说最简单的方法是解压到home目录,进入目录,然后在目录中工作。或者随便放哪里,把新目录加到Python的搜索路径中。
    • 做了很多尝试,都没有成功。虽然最后成功了,但是还是没明白。

    0. 下载swampy,解压之后是swampy-2.1.5文件夹,如果把文件夹改成swampy,能实现 import swampy不报错,但是不能成功导入swampy.TurtleWorld。错误因为其中另外一个模块Gui找不到。

    1. 如果直接把一个.py文件放到Lib目录下面就能import,但是放到swampy的目录下之后就找不到了。

    2. Windows的Path和Python的搜索路径区别。
    用echo %path%能看到我把这个新的目录加入了Windows的path里面。
    但是用sys.path就没有这个地方,然后两个的结果也不太一样。
    sys.path.append(r'路径'),把path加入是解决方案,但是如果重启,sys.path里面就没有了。

    解决

    • 也就是说每次运行下加入路径,或者进入到swampy所在目录就能导入模块。
    • 更多的内容官网里面说得很多https://docs.python.org/3.6/tutorial/modules.html


    ----ฅ(*ΦωΦ)ฅ---- cognata ad sidera tendit...
  • 相关阅读:
    LeetCode344
    LeetCode18四数之和扩展N数之和
    LeetCode383赎金信
    2018-2020创业总结
    LeetCode454四数相加
    普通dll项目添加WPF的Window对象
    WPF中RadioButton的数据绑定
    02 C# 文件压缩与解压
    WPF 使用附加属性声明 ICommand
    自定义WPF分页控件
  • 原文地址:https://www.cnblogs.com/Xeonilian/p/think-python-TurtleWorld-exersice.html
Copyright © 2020-2023  润新知