惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy & Cybersecurity Law Blog
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
B
Blog RSS Feed
罗磊的独立博客
V
V2EX
V
Visual Studio Blog
博客园 - 叶小钗
W
WeLiveSecurity
小众软件
小众软件
K
Kaspersky official blog
美团技术团队
雷峰网
雷峰网
阮一峰的网络日志
阮一峰的网络日志
Martin Fowler
Martin Fowler
Recorded Future
Recorded Future
Project Zero
Project Zero
Hugging Face - Blog
Hugging Face - Blog
Engineering at Meta
Engineering at Meta
Security Latest
Security Latest
Microsoft Azure Blog
Microsoft Azure Blog
V
Vulnerabilities – Threatpost
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
Help Net Security
Help Net Security
博客园 - Franky
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Forbes - Security
Forbes - Security
M
MIT News - Artificial intelligence
H
Hacker News: Front Page
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
Spread Privacy
Spread Privacy
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Google Online Security Blog
Google Online Security Blog
PCI Perspectives
PCI Perspectives
The Last Watchdog
The Last Watchdog
AI
AI
N
News | PayPal Newsroom
D
DataBreaches.Net
Cloudbric
Cloudbric
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog

Nik Ogura

Nice People Who Give Us Money | Nik Ogura Gambling on Failure | Nik Ogura DDCRI: Declarative, Deterministic, Continuously Reconciling Infrastructure | Nik Ogura Stop Holding Out for a Hero | Nik Ogura Don't Paint Yourself Into a Corner | Nik Ogura Most Infrastructure as Code Is Broken — and Reconciliation Is Only Half the Reason | Nik Ogura Continuous Acceptance Tests | Nik Ogura There's More Than One Way to Get Observability Right | Nik Ogura Put Dex In Front of Google OAuth | Nik Ogura Incident Management | Nik Ogura C-Style Thinking vs Go-Style Thinking | Nik Ogura 'Can' vs 'Does' | Nik Ogura Control Repositories | Nik Ogura Trunk-Based Development | Nik Ogura Web3 Is Just Infrastructure With a Hoodie | Nik Ogura "Design Me a Highly Resilient Database" | Nik Ogura Security Is Infrastructure | Nik Ogura Metrics, Logs, Traces, and Events: What's Actually Different | Nik Ogura Distributed Tracing: A Practical Guide | Nik Ogura Prometheus and OpenTelemetry: How They Fit Together | Nik Ogura Puppets and Octopi: Why Top-Down Orchestration Hits a Wall | Nik Ogura The Best Dog Trainer in the World - Or Why Getting Better Isn't Helping | Nik Ogura FluxCD vs ArgoCD: Architectural Comparison | Nik Ogura GitOps | Nik Ogura GitHub Actions Reference Implementation | Nik Ogura Shell Functions | Nik Ogura Engineering Standards | Nik Ogura Cross-Cloud Kubernetes Clusters with AWS IRSA and Talos Linux | Nik Ogura FITFO - Figure It The (Fun?) Out | Nik Ogura Golang Design Tips | Nik Ogura Auto Updating AMI's on a Rolling Window with Terraform | Nik Ogura The Documentation Problem | Nik Ogura Vault Operator Notes | Nik Ogura Coding Standards (especially in Golang) | Nik Ogura TDD (Test-Driven Development) | Nik Ogura Managed Secrets | Nik Ogura Using CircleCI as if it was a Maven Repo | Nik Ogura Dynamic Binary Toolkit: Tools that automatically keep themselves up to date! | Nik Ogura Access and Identity that Just Works | Nik Ogura LocalEnv | Nik Ogura One Shot OpenStack Liberty Installer | Nik Ogura IAM Beyond AWS or Hacking Hacks, and the Hackers who Hack Them | Nik Ogura
Python Development on MacOS | Nik Ogura
2017-12-09 · via Nik Ogura

Some potentially timesaving tips and tricks I’ve found on my Pythonic journey.

Don’t Use the Default Python Interpreter

You could, and it might not be a total disaster, pain in the butt, and it might not expose you to all sorts of interesting usability and security problems.

Then again, you could install the exact version of Python you desire, and configure it with the precise versions of the libaries you desire, and have developed against, and know to work with your application. ‘Nuff said.

Pre Setup

Install Homebrew

Homebrew is billed as “The missing package manager for OS X”. It rocks. It’s simple, it works, and all the cool kids are using it.

Not only does it install stuff, keeps versions and updates straight, gives reproducible results, is well documented and maintained, but it does its thing in userspace, so you don’t need to use ‘sudo’. This is a good thing. Install homebrew thusly:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Once you have Homebrew, install Python 2.7 and virtualenv via homebrew:

    brew install python
    pip install virtualenv
    

You could go whole hog and install Python 3. If you’re working in a quazi-vacuum with no other Python development going on, you probably should do Python 3, as you’ll be more future proof.

I work for iOS Systems, and we have more than a few Python apps in flight, and unfortunately they’re all Python 2.7.x so, I’m stuck writing for Python 2.7 for the time being until we can upgrade everything across the board. If you’re using my libraries, you’re stuck too. Sorry. My only promise is that I’m well aware of the fact that eventually we’ll all have to upgrade, and I’m writing things so that that upgrade shouldn’t be too bad- in theory anyway. Fingers crossed.

Command Line Setup

Choose a location to store your virtual environments. The author uses ~/src/python. This directory will be referred to hereafter as VIRTUALENV_DIR

Create a virtualenv for your project:

    virtualenv <VIRTUALENV_DIR>/<PROJECT>
    

This will create the virtual environment. You can use any path, just so long as you remember where you put it. You’ll need it later.

NOTE: Do not perform this step if you’re using IntelliJ IDEA or PyCharm as your IDE. IntelliJ and PyCharm don’t like virtualenv’s they did not create themselves. If you’re using a JetBrains IDE, proceed to ‘IDE Setup below’.

Then you can activate it thusly:

    source <VIRTUALENV_DIR>/<PROJECT>/bin/activate
    

And install the requirements:

    pip install -r requirements.txt
    

You could also use virtualenvwrapper if you’re going to work mostly from the command line. It’s well thought of, and works well. I use IntelliJ, so you’ll have to follow the instructions in the link above for help with virtualenvwrapper.

IDE Setup

If you’re using a JetBrains IDE (Intellij or PyCharm), the following is how I do things. There are other ways to do it, but some ways that should work give surprising or inconsistent results. My methods are not the only legitimate ones, but they’re the ones that work for me.

First thing you want to do is check out the code from the command line:

    git clone [email protected]/org/project.git
    

Then create a new project with File -> New -> Project -> Python and under SDK choose New -> Python -> create virtualenv. There is a dialog for creating projects directly from a VCS url. I’ve had mixed results with it in the past, and now prefer to clone the repos manually, then point the IDE at the code. YMMV.

You can also create an ‘empty’ generic project. I’ve had bad luck with that. IntelliJ IDEA is first and foremost a Java IDE, and Java is totally obsessed with the ‘type’ of everything. IntelliJ does better if it knows the ‘type’ of your project. This is best done when you create the project. Setting it later doesn’t always seem to work. Maybe PyCharm doesn’t have this issue, being focused specifically on Python. It’s not an option for me, who floats between Java, Python, Ruby, and all sorts of other things. IntelliJ is my home.

Generally speaking, I specifically ignore the .iml and .idea directories in git, and don’t check them in. I don’t hesitate to ‘recreate’ the project files when things get screwey. Just use the File -> New -> Project -> Python menus, and it’ll pop warnings about overwriting the .iml file and .idea directory. Just let it overwrite, and often you’re back in business just like that. Again, YMMV.

The virtualenv’s created by IntelliJ are exactly the same as the ones you create from the command line, but for some reason IntelliJ doesn’t figure out where all the pieces are unless it creates it itself. You could presumably tell it where everything is and have it all work, but do you really need that kind of trouble?

Intellij, with a properly configured virtualenv that it recognizes, will automatically monitor requirements.txt, and will ask you if you want to load modules that you don’t have yet. It’s pretty slick.

IDE Python Trick

Check out LocalEnv for a method of giving you easy access to a command line automatically pre-prepped for working with the virtualenv your IDE is using.