반응형
반응형

[python] Ty - 빠른 Python 타입 체커 및 언어 서버  

 

https://github.com/astral-sh/ty

 

GitHub - astral-sh/ty: An extremely fast Python type checker and language server, written in Rust.

An extremely fast Python type checker and language server, written in Rust. - astral-sh/ty

github.com

 

  • ty Rust로 작성된 매우 빠른 Python 타입 검사기  언어 서버
  • 아직은 프리릴리즈 소프트웨어로, 프로덕션에서 사용하기에는 준비되지 않음
  • Astral의 초고속 파이썬 Linter인 Ruff 저장소에서 개발이 진행 중이며, 안정성 기능 완전성을 목표로 함
  • MIT 라이센스

https://astral.sh/

  • "파이썬 개발도구는 훨씬 더 빠를 수 있습니다"
  • 초고속 Python Linter인 Ruff를 만든 Chalie Marsh가 설립한 회사
  • Ruff를 확장하고, Ruff와 비슷한 고성능 개발도구를 만들어서 파이썬 에코시스템을 빠르게 만드는 것이 목표
  • 모두 오픈소스로 만들어 공개할 것이며, 그 기반으로 유료 서비스를 제공할 예정
  • Accel 이 리드하여 $4m 시드펀딩으로 시작

 


Getting started

Installation

uv tool install ty
 

or add ty to your project:

uv add --dev ty

# With pip.
pip install ty
 

First steps

After installing ty, you can check that ty is available by running the ty command:

ty
An extremely fast Python type checker.

Usage: ty <COMMAND>

...
 

You should see a help menu listing the available commands.

For detailed information about command-line options, see the CLI documentation.

Checking your project

ty check
 

 

반응형
반응형

소프트웨어를 무료로 배포하는 방법

https://simonwillison.net/2025/Apr/28/give-it-away-for-free/

 

Giving software away for free

If you want to create completely <strong>free software</strong> for other people to use, the absolute best delivery mechanism right now is static HTML and JavaScript served from a free web …

simonwillison.net

 

 

https://pyodide.org/en/stable/

 

 

 

  • 다른 사람을 위한 무료 소프트웨어를 만들고 싶다면:
    • 정적 HTML + JavaScript로 제공
    • 무료이면서 신뢰할 수 있는 웹호스팅 이용
  • WebAssembly Pyodide 덕분에:
    • 클라이언트 측 Python 애플리케이션 제공 가능
  • 서버 기반 서비스는 추천하지 않음:
    • 서버는 업그레이드와 비용 관리가 필요해 시간이 지나면 부담이 됨
  • 2025년 추천 플랫폼:
    • GitHub Pages (공개 저장소용, 17년 넘게 안정적)
  • 과거 추천했지만 이제는 비추천:
    • Heroku (2022년 Salesforce 인수 후 신뢰도 하락)
  • 추가 권장 사항:
    • 오픈 소스 라이선스로 배포
    • 바로 실행 가능한 링크 제공

 

 

Getting started

Try it online

Try Pyodide in a REPL directly in your browser (no installation needed).

Setup

There is a complete example that you can copy & paste into an html file below. To include Pyodide in your project you can use the following CDN URL:

https://cdn.jsdelivr.net/pyodide/v0.27.5/full/pyodide.js

You can also download a release from GitHub releases or build Pyodide yourself. See Downloading and deploying Pyodide for more details.

The pyodide.js file defines a single async function called loadPyodide() which sets up the Python environment and returns the Pyodide top level namespace.

async function main() {
  let pyodide = await loadPyodide();
  // Pyodide is now ready to use...
  console.log(pyodide.runPython(`
    import sys
    sys.version
  `));
};
main();

Running Python code

Python code is run using the pyodide.runPython() function. It takes as input a string of Python code. If the code ends in an expression, it returns the result of the expression, translated to JavaScript objects (see Type translations). For example the following code will return the version string as a JavaScript string:

pyodide.runPython(`
  import sys
  sys.version
`);

After importing Pyodide, only packages from the standard library are available. See Loading packages for information about loading additional packages.

Complete example

Create and save a test index.html page with the following contents:

<!doctype html>
<html>
  <head>
      <script src="https://cdn.jsdelivr.net/pyodide/v0.27.5/full/pyodide.js"></script>
  </head>
  <body>
    Pyodide test page <br>
    Open your browser console to see Pyodide output
    <script type="text/javascript">
      async function main(){
        let pyodide = await loadPyodide();
        console.log(pyodide.runPython(`
            import sys
            sys.version
        `));
        pyodide.runPython("print(1 + 2)");
      }
      main();
    </script>
  </body>
</html>

Alternative Example

<!doctype html>
<html>
  <head>
    <script src="https://cdn.jsdelivr.net/pyodide/v0.27.5/full/pyodide.js"></script>
  </head>

  <body>
    <p>
      You can execute any Python code. Just enter something in the box below and
      click the button.
    </p>
    <input id="code" value="sum([1, 2, 3, 4, 5])" />
    <button onclick="evaluatePython()">Run</button>
    <br />
    <br />
    <div>Output:</div>
    <textarea id="output" style="width: 100%;" rows="6" disabled></textarea>

    <script>
      const output = document.getElementById("output");
      const code = document.getElementById("code");

      function addToOutput(s) {
        output.value += ">>>" + code.value + "\n" + s + "\n";
      }

      output.value = "Initializing...\n";
      // init Pyodide
      async function main() {
        let pyodide = await loadPyodide();
        output.value += "Ready!\n";
        return pyodide;
      }
      let pyodideReadyPromise = main();

      async function evaluatePython() {
        let pyodide = await pyodideReadyPromise;
        try {
          let output = pyodide.runPython(code.value);
          addToOutput(output);
        } catch (err) {
          addToOutput(err);
        }
      }
    </script>
  </body>
</html>

Accessing Python scope from JavaScript

All functions and variables defined in the Python global scope are accessible via the pyodide.globals object.

For example, if you run the code x = [3, 4] in Python global scope, you can access the global variable x from JavaScript in your browser’s developer console with pyodide.globals.get("x"). The same goes for functions and imports. See Type translations for more details.

You can try it yourself in the browser console. Go to the Pyodide REPL URL and type the following into the browser console:

pyodide.runPython(`
  x = [3, 4]
`);
pyodide.globals.get('x').toJs();
// >>> [ 3, 4 ]

You can assign new values to Python global variables or create new ones from Javascript.

// re-assign a new value to an existing variable
pyodide.globals.set("x", 'x will be now string');

// add the js "alert" function to the Python global scope
// this will show a browser alert if called from Python
pyodide.globals.set("alert", alert);

// add a "square" function to Python global scope
pyodide.globals.set("square", x => x*x);

// Test the new "square" Python function
pyodide.runPython("square(3)");

Accessing JavaScript scope from Python

The JavaScript scope can be accessed from Python using the js module (see Importing JavaScript objects into Python). We can use it to access global variables and functions from Python. For instance, we can directly manipulate the DOM:

import js

div = js.document.createElement("div")
div.innerHTML = "<h1>This element was created from Python</h1>"
js.document.body.prepend(div)

 

반응형
반응형

[python] python  코드를 exe 실행 파일로 생성하는 방법

 

PyQt5를 사용하는 파이썬 스크립트를 실행 파일로 만들기 위해서는 몇 가지 단계를 거쳐야 합니다. 여기서는 가장 일반적으로 사용되는 PyInstaller 라이브러리를 이용하여 exe 파일을 만드는 방법을 설명합니다.

 

1. PyInstaller 설치

아직 PyInstaller가 설치되어 있지 않다면, 명령 프롬프트 또는 터미널을 열고 다음 명령어를 실행하여 설치합니다.

 

pip install pyinstaller

 

 

2. 실행 파일 생성

파이썬 스크립트 파일(your_script_name.py, 여기서는 파일명을 stock_tracker.py라고 가정하겠습니다)이 있는 디렉토리로 이동한 후, 다음 명령어를 실행합니다.

 

pyinstaller --onefile --windowed stock_tracker.py

 

각 옵션의 의미는 다음과 같습니다.

  • --onefile: 하나의 실행 파일로 모든 의존성을 묶습니다.
  • --windowed 또는 -w: 콘솔 창이 나타나지 않는 윈도우 애플리케이션으로 만듭니다. PyQt5 GUI 애플리케이션이므로 이 옵션을 사용하는 것이 적절합니다.
  • stock_tracker.py: 실행 파일로 만들 파이썬 스크립트의 이름입니다.

3. 생성된 실행 파일 확인

명령어를 실행하면 dist라는 폴더가 생성됩니다. 이 폴더 안에 stock_tracker.exe (또는 스크립트 이름에 따라 다른 이름일 수 있습니다) 파일이 생성됩니다. 이 파일이 바로 실행 가능한 파일입니다.

주의사항:

  • 의존성 문제: PyInstaller가 자동으로 모든 필요한 의존성 라이브러리를 포함하지 못할 수 있습니다. 실행 파일 실행 시 오류가 발생한다면, 누락된 라이브러리를 확인하고 PyInstaller 옵션을 조정해야 할 수 있습니다. 예를 들어, 특정 데이터 파일이나 라이브러리를 명시적으로 포함해야 할 수도 있습니다.
  • 바이러스 검사: 생성된 exe 파일은 때때로 백신 프로그램에 의해 오진될 수 있습니다. 이는 PyInstaller가 실행 파일을 패키징하는 방식 때문일 수 있으며, 코드 자체에는 문제가 없을 가능성이 높습니다.
  • plyer 알림: plyer 라이브러리를 사용하여 알림 기능을 구현했으므로, 해당 라이브러리가 제대로 작동하는 환경에서 실행해야 알림이 표시될 수 있습니다. 일부 시스템 구성에서는 알림이 제대로 표시되지 않을 수도 있습니다.

위 단계를 따르면 파이썬 스크립트를 독립적인 실행 파일로 만들 수 있습니다. 생성된 .exe 파일을 다른 윈도우 환경에서도 파이썬 설치 없이 실행할 수 있습니다.

 

 

반응형
반응형

[python] SVG to PNG, install cairosvg

 

pip install cairosvg

 

 

import os
import cairosvg

# 변환할 폴더 경로
input_folder = "img"
output_folder = "output_png"

# 출력 폴더가 없으면 생성
if not os.path.exists(output_folder):
    os.makedirs(output_folder)

# img 폴더 안의 모든 SVG 파일 변환
for filename in os.listdir(input_folder):
    if filename.lower().endswith(".svg"):  # 확장자가 .svg인 파일만 처리
        input_path = os.path.join(input_folder, filename)
        output_path = os.path.join(output_folder, filename.replace(".svg", ".png"))

        # SVG → PNG 변환
        cairosvg.svg2png(url=input_path, write_to=output_path)
        print(f"변환 완료: {filename} → {output_path}")

print("✅ 모든 변환이 완료되었습니다!")

📂 폴더 구조 예시

🏆 설명

  1. img 폴더 안의 모든 .svg 파일을 찾음.
  2. 각 .svg 파일을 .png로 변환하여 output_png 폴더에 저장.
  3. 변환이 완료되면 메시지를 출력.

✅ 이 코드를 실행하면 img 폴더 안의 모든 SVG 파일이 output_png 폴더에 PNG로 변환되어 저장됩니다! 🚀

반응형
반응형

 "Life is short (You need Python)"
인생은 짧으니, 당신은 파이썬이 필요하다.   
- Bruce Eckel

 

반응형
반응형

터미널에서 장고 프로젝트 디렉토리인 mysite 로 이동 합니다.

(.conda) (c:\dev\django\.conda) C:\dev\django>cd mysite

터미널에서 mysite 디렉터리로 이동 후 python manage.py runserver 라는 명령어를 실행합니다.

(.conda) (c:\dev\django\.conda) C:\dev\django\mysite>python manage.py runserver

서버가 정상적으로 실행되었다면 웹브라우저를 이용하여 http://127.0.0.1:8000/ 에 접속합니다.

 

http://127.0.0.1:8000/

 

문서 :   https://docs.djangoproject.com/en/5.1/  

 

 
반응형

+ Recent posts