python 建立項目

來源:互聯網
上載者:User

標籤:too   esc   模組   res   cts   tool   \n   asi   conda   

項目骨架
  • nose 測試架構
Windows 10 配置建立骨架項目目錄

Windows 10 的 PowerShell

mkdir projectscd projects/mkdir skeletoncd skeleton/mkdir bin, NAME, tests, docsNew-Item -type file  NAME/__init__.py, tests/__init__.py  # 建立初始化模組

bin 檔案用來存放命令列啟動並執行指令碼,但是這不是存放模組的地方。

建立 setup.py 用來安裝項目

setup.py

try:    from setuptools import setupexcept ImportError:    from distutils.core import setupconfig = {    ‘description‘: ‘My Project‘,    ‘author‘: ‘My Name‘,    ‘url‘: ‘URL to get it at.‘,    ‘download_url‘: ‘Where to download it.‘,    ‘author_email‘: ‘My email.‘,    ‘version‘: ‘0.1‘,    ‘install_requires‘: [‘nose‘],    ‘packages‘: [‘NAME‘],    ‘scripts‘: [],    ‘name‘: ‘projectname‘}setup(**config)

編輯上面的檔案,把自己的連絡方式寫進去,這樣每次複製時就不需要更新了。

最後需要一個簡單的測試專用的骨架檔案叫 tests/NAME_test.py

NAME_tests.py

from nose.tools import *import NAMEdef setup():    print("SETUP!")    def teardown():    print("TEAR DOWN!")    def test_basic():    print("I RAN!")

可以運行 ls -R 查看目錄結構。

返回 tests/ 目錄的上一層,運行測試:

nosetests
使用這個骨架

以後每次要建立一個項目時,只要做下面的事情就可以了:

  • 複製這份骨架目錄,把名字改成新項目的名字。
  • 將 NAME 目錄更名為你的項目的名字,或者你想給自己的根模組起的名字。
  • 編輯 setup.py,讓它包含新項目的相關資訊。
  • 重新命名 tests/NAME_test.py,把 NAME 換成你的模組的名字。
  • 使用 nosetests 檢查有無錯誤。
  • 開始寫代碼。

樣本:

cp -r  .\projects\ xintcd xint\skeletonRename-Item NAME xintRename-Item -Path ‘D:\APP\xint\skeleton\tests\NAME_test.py‘ -NewName ‘D:\APP\xint\skeleton\tests\xint_test.py‘
get-help Rename-Item -examples  # 擷取協助
python 打包工具 distutilssetuptools 分析建立 python 虛擬環境

如果 anaconda 的捷徑消失(Windows 10),則可以試試以下操作:

  • win+R 輸入 cmd 進入命令列,跳轉到 Anaconda 的安裝目錄,然後執行
    python .\Lib\_nsis.py mkmenus
  • 然後再查看開始菜單,你想要的 Anaconda 的相關捷徑就出現了
使用 Visual Studio 建立項目

python 建立項目

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.