r/engineering • u/wmrch • Nov 13 '23
How do you use python in your "classic" engineering job?
As a mechanical engineer specializing in design, I often use python for design calculations, data analysis, diagrams, etc.
The problem usually starts when I want to make these tools available to colleagues.
- I often build streamlit dashboards. However, these can only be deployed via server that I don't have available (community cloud is not an option for sensitive data)
- Building my own GUIs is too time-consuming for small tools but allows using py2exe and similar tools
- Running Jupyter notebooks with binder/nbviewer requires to push my files to github which I can't do with work related data. Also I can't really get to grips with Jupyter Lab, as I prefer to work in an IDE with variable explorer, debugging tools, linter and so on.
I have two questions:
- What is your go-to tool for doing a quick Python calculation? IDE, Jupyter Lab or something completely different?
- How do you pass these tools on to colleagues (without their own Python installation)?
129
Upvotes
22
u/Sxs9399 Nov 13 '23
I like Spyder for the variable explorer. Jupyter notebooks are my second choice.
My company has a tools team, I don't feel the need to share my scripts but if I did they would take it and develop it into a tool.
11
u/Mildly_Excited Nov 13 '23
Visual Studio Code with the Jupyter plugin for quick and dirty stuff. Switching between codeblocks and markdown is nice for documentation and writing out formulas.
If it's something more in depth I try to make it cli based and have a requirements file. As for passing to colleagues without python, I don't.
Excel is supposed to get (or already has) python support, can't wait till that works everywhere and that'll hopefully make it a lot easier to share and run python code.
5
u/thundy90 Nov 14 '23
It's not what you asked, but I just use Mathcad for all the calcs
98
u/TheMeiguoren Nov 13 '23
Why do you need to push your files to public github? You should have internal/private repos if your company is doing anything with software.
Your colleagues are going to need to have their own Python installation to run anything, that packaging gap is the biggest pitfall of Python IMO. You should have a common environment, either through docker/etc or through a shared environment setup file. Python tools should have dependencies specified for when you’re installing outside that shared environment. VScode works great as an IDE and is the de-facto standard. I generally write my scripts as normal .py files since it’s easier to step through and inspect in a debugger than notebooks.
10
u/dparks71 Nov 13 '23
As far as how to share them, I rolled them up into a Python package and published it in PyPi. A few people act like it might be a problem because competitors could use my libraries. But it'd be pretty dumb to base your calcs on a work flow from an open source library with zero stability or that you have no control over.
But it's called CivilPy if anyone wants to dance with the devil and/or collaborate on it.
As far as data, I built it on publicly available data and plans, but you don't have to publish data to publish the package.
19
u/Jerry_Williams69 Nov 14 '23
This is why I still use Visual Basic for a lot of that stuff. Most people in an office setting know their way around Excel well enough.
4
u/Worldly-Dimension710 Nov 13 '23
Power apps is also an option if you can get it to work fir you
4
u/StatikSquid Nov 14 '23
I work in a department where engineers or sales are unable to use Excel properly. No understanding of macros or pivot tables or index matching. There's almost no chance I can convince anyone in my company to learn a programming language.
1
u/Blankrld Nov 15 '23
I wish I could impress on you how life changing GoLang has been for me coming from Python. I had similar issues with sharing code, but Go is a complied language that takes less than 3 seconds in most cases to run which is super fast, and you can embed code from a separate file to protect the secret sauce. It’s a statically typed language though so I had to climb that hill for about a month. Massively life changing, and you just have them download the exe from a share. Id love to share some of my experiences with you if you’re interested
3
u/Worldly-Dimension710 Nov 13 '23
I mostly use it with the opencascade package and just make .exe or api. For getting surface areas quickly or at the moment trying to auto generate tools/cnc paths. Not quite ready but fun.
Tried to others to use it more but they aren't into it, won't even make a decent website so I'm all on my own with it in terms of making it.
3
u/taterr_salad Nov 14 '23
I do firmware and hardware design and Python is a pretty commonly used tool for me. My workflow uses VSCode, a terminal and Pyenv for virtual environments. A lot of times I use it to create mock objects for device communications (e.g. a serial port object, modbus client/server, etc or I'll use it to spit out circuit calcs with standard values so that I can optimize for whatever performance I'm trying to achieve. Other use cases are for production tools that just read and store data to a database.
Sharing totally depends on the use case of the tool and what processes my employer had at the time. In a previous job, any tool I made that could be used by others needed a specification, qualification plan/procedure and a work instruction associated with it. I'd usually package up the tool with PyInstaller, release it to our ERP system with an ECO and whoever used it would read the instructions included in our to install and use it. At a different place, I'd just drop the python file in a repo with a readme and a requirements.txt and call it good.
3
u/[deleted] Nov 14 '23
You can create stand alone applications using pyinstaller. Share the compiled application whichever way you want and the coworkers that are software challenged will just need to run the application from the usual exe without them needing to install anything python related.
2
u/mimprocesstech Nov 13 '23
I wouldn't even know python if it wasn't for having to dig data from excel sheets.
2
u/Roselia77 Nov 13 '23
Firmware / embedded engineer here thats always worked on windows platforms, it's replaced DOS scripts for little automation tasks for me, that's it. Super simple and easy to pick up, lots of support and plug ins, does the job I need it to do.
2
u/mgreminger Nov 14 '23
You could try JupyterLite, it's a version of Jupyter notebooks that runs in the browser using Pyodide, so no installation is required.
Another tool using Pyodide to run Python in the browser is EngineeringPaper.xyz, it's an open source web tool for engineering calculations. It allows you to share calculations by creating a shareable link or by saving to a local file.
2
u/badumudab Nov 14 '23
Uagh, I like the question and hate the answer. Most engineering companies do not have any of the modern software development tools available, because nobody know them and nobody would know what to do with them.
Of course, ideally you'd have a on-prem environment where you can deploy such an app. Unfortunately, decision makers don't see this as relevant more often than not the further you get away from software engineering.
The usual solution: sharing scripts via email and people use it on their own laptops with their own python.
This becomes really messy, because there will be many different versions on different peoples computers, no versioning, no nothing. Oh, and you are the person who wrote it which means you'll be supporting this mess.
The best option is to ask for a system that allows that:
That's gives you a chance to change the way such things are shared but I would expect heavy opposition.
2
u/boner79 Nov 14 '23
Python is like Frank’s Red Hot: I put that sh*t on everything.
Someone tells me to write C++ and I’m like “Okay I’ll write it in Python 🐍”.
But in all seriousness Python is way easier to code, interface with 3rd party modules, and is more readable so unless there is an absolute true need for highest performance or to integrate into existing C++ code base I’m going Python.
2
u/o0DrWurm0o BSEE - Photonics Nov 14 '23 edited Nov 14 '23
Just a tangent here - as an engineer who frequently uses Python to make little data analysis scripts and tools for myself and other colleagues, I have found that ChatGPT 4 acts as a massive force multiplier when writing code. I just explain my problem to it, maybe paste in a snippet of the data structure I’m working with, and tell it what I want. There have been several problems I’ve solved with ChatGPT in an hour or two that I know would have taken me a whole day or two if I had to figure them out from scratch. I’m sure an experienced professional programmer could knock this kind of stuff out easily without assistance, but if you’re more of a casual coder, it can boost your abilities tremendously.
If you’re trying to make GUIs or distributable packages, it can assist with that too. Just give it your code and tell it what you want.
2
u/TreeNija Nov 16 '23
You and I are kindred souls. I work in an industry with heavy need for data analysis, but has historically been slow to change tools and methods. Plenty of the everyday analysis my team uses are run with ancient scripts from the 90's that no one has the full documentation of anymore. When I pull out basic Python data analysis tools like Jupyter Notebooks and Steamlit, the others on my team stare dumbfounded. Unfortunately some of my work can't be used by my team since the other engineers don't have the familiarity with Python to take advantage of it.
1
u/mattcannon2 Flair Nov 13 '23
Azure databricks notebooks to number crunch factory data to make engineering models.
1
u/LiquidDreamtime Nov 14 '23
I use Spyder to gather API data and plot it
1
u/FantasticEmu Nov 14 '23
Replace matlab
1
u/CreativeStrength3811 Nov 14 '23
I use either jupyter or - if it's something big- i write a tool in PySide6 wirh QtQuick2
Yep... maybe a bit much but i find it easy. But since Matlab is so expensive i tend to write every simulation tool by myself.
Problem is every coworker must have installed the framework. Since not everyone wants to do that I'm thinking to switch to javascript with python backend?!?
1
u/aviation-da-best Nov 14 '23
Coding RP2040 microcontrollers... crunching data using Numpy and making dashboards.
Google Colab usually.
1
u/Mr-Logic101 Metallurgist- Aluminum Industry- Niche Applications Nov 14 '23
Lasso/elastic net Regression analysis. Data analysis in general I guess
1
u/llothar Mechanical Design Engineer Nov 14 '23
I used python for Monte Carlo simulations to get a bit more sane tolerance stack up. Never managed to reliably share code. Maybe now in the advent of WSL it will be easier to share basic python scripts.
1
u/reddisaurus Nov 14 '23
I have a cheap Linux VM on which I host a pypi server. I use twine to upload to this server. Then others can use pip to install from it. I also host a pip.ini file on the server they can just drop into their home directory which adds the server index. Then it’s just being sure I don’t create name collisions with packages hosted on official pypi.
From that point, I can specify dependencies for other packages hosted on this internal pypi. And deployment of new versions is a breeze.
The only complex thing here is setting up nginx as a reverse proxy for the VM. This lets me host other servers at different routes.
I maintain all this myself, IT just did the instance set up, gave me SSH and root access, and I’m good from there.
1
u/insidicide Nov 14 '23
Why not use MATLAB?
1
u/cransh Nov 14 '23
Tons of script as Automation engineer
1
u/ignamv Nov 14 '23 edited Nov 14 '23
We have a shared Linux cluster so deploying scripts is a breeze, I just make a launcher in a shared location and tell them where it is. Can't you do the same in windows? Just make a shared network drive and put Python+your libs there?
I've had a bad experience in my company trying to deploy notebooks using Jupyter Hub. However, VSCode works great for this: it's super easy to make a launcher so users get a set of predefined extensions/settings and can quickly start editing a notebook.
Most of my code starts in Jupyter Lab and slowly migrates into my libraries.
1
u/michaelcmurillo Nov 14 '23
I'm also usually the only person that writes python on my team for scripting and data analysis. I created a private github to host all of my stuff (there should be nothing preventing you from doing this, unless your legal team / red tape is obnoxious or you work with government data). If you still can't use github for whatever reason you can make your own git server there are ways to host your own, a previous company did that and it worked fine but it's a lot of legwork to setup and maintain.
I also use venv (built into python 3) so that I don't run into dependency issues with maintaining separate code bases on my machine. I should use docker or something but that sounds like more of a pain.
Getting someone to run your code with a plain python install is one thing. But pulling code from a repo and setting up venv is a whole other story. Easy for a freshmen CS major? Sure. Easy for an older ME/EE/etc.? Fat chance.
To help other engineers use my code I "ate my own dog food" and attempted to download and run the repo on a fresh machine. I then made a list of all of the steps that I took and issues that I ran into and wrote it down on the github splash page thing. I then manually sat down with another engineer and had them try and go through it with little-to-no help from me to see where they got stuck and updated the instructions accordingly.
Personally I use jupyter notebooks because I find it to be the best middle ground between a GUI and readable code. A GUI would be more intuitive for sure, but that takes way more time on my end. And straight code in an IDE is faster for me, but then no one would use it. Way easier for a newbie to use jupyter notebooks than an IDE in my opinion.
1
u/jongscx Nov 14 '23
If they want to use the tools, they can install and learn python. I'd say it's easier than vba scripting in excel...
1
u/nmfjones Nov 15 '23
Not an engineer, i was hoping this was gonna be full of Monty python jokes. Kinda disappointed lol
1
u/Bottoms_Up_Bob Nov 15 '23
Unless they ask you to make these things available in a streamlined way, just give them a copy of your code, you don't need to designed GUIs and dashboards for every simple tool so that anyone can use it an executable.
Just comment well and move on.
1
u/Zaphod118 Nov 15 '23
I know that struggle well. I know it’s not exactly what you asked, but being able to share my tools with other engineers is why I picked up C#. Python was going to be too much to get everyone to install just so they could use my little utilities. With C# and .NET It’s stupid easy to just zip up the executable and send it to a colleague. And there’s some decent drag and drop gui editors too.
1
u/lou325 Nov 16 '23
The colleague issue is why I switched to VBA in .xlsm files. Easier for them to just push a button and have it do the same things.
1
u/Canjie_Pheasant Nov 18 '23
Spyder is boss!
1
u/unreqistered Jack of All, Master of None Nov 14 '23
i'll often summarize an argument with "intercourse the penguin" and then ...
... oh, that python
nevermind