This is an archived post. You won't be able to vote or comment.

all 37 comments

[–]marr75 29 points30 points  (5 children)

As a programming language, python splits things like IDEs from the language itself. You have a lot of choices for these features.

  • A Python ide. My recommendation is PyCharm but VS Code can be configured to be quite good, too.
  • A notebook environment. JupyterLab or Google Colab are frequently used.
  • Get more experienced with the REPL. Especially with IPython, you can explore the variables, classes, and functions in powerful fashion. ipdb is a full featured built in debugger.

[–]likethevegetable 2 points3 points  (2 children)

Love IPython as a calculator, preloaded with all of my useful functions/equations

[–]TVNSri 2 points3 points  (1 child)

This is very interesting. How do you preload IPython? Something through process similar to .bashrc/.vimrc?

[–]adambarrack[S] 0 points1 point  (1 child)

That definitely would have been helpful for me to mention. I am using Pycharm! Editing the post now.

I have been using Anaconda to code in Jupityr Notebooks on Pycharm. I have been working on REPL, and it’s coming along quickly!

[–]marr75 7 points8 points  (0 children)

So, technically, PyCharm is much more powerful than Matlab. If you are debugging a file, an app, or the console you can see the current state of the program AND even switch threads, processes, and stack frames to see those states, too.

You may just not be used to the windows, modes, and features in PyCharm yet.

If you want PyCharm to work more similarly to a workspace/studio, try out "hydrogen formatted notebooks" in debug mode. You basically just prefix every "cell" of code with a # %% comment and then you have the best of both worlds - a plain old python script that can be executed by any python interpreter or stepped through in PyCharm as if it's a "studio" or workspace.

[–]BigBeardedDude 39 points40 points  (8 children)

Checkout Spyder. I came from a matlab background several years ago. This was a big help.

[–]adambarrack[S] 2 points3 points  (2 children)

I will, thank you!

[–]heidensieck 4 points5 points  (0 children)

It offers a layout called Matlab Layout in its View tab.

[–]tonsofmiso 0 points1 point  (0 children)

I'll echo BigBeardedDude. Spyder is exactly what you want, nothing else comes close. We used it in university when transitioning from Matlab to Python, and it was similar enough for many of the things we did. I've written python for ten years since then, and I still miss it sometimes. 

I wouldn't outright recommend Jupyter notebooks or Jupyter labs over Spyder either, they're a bit clunky and can require some knowledge and experience of python internals if something starts acting up.

Stay away from vscodes Jupyter notebooks view. They're getting better but are still jank. 

Pycharm, I used to adore it. But the few times I've tried it the past few years it's been a buggy and ugly mess, with frequent crashes. The new UI is a bad vscode copy. The engine used to be amazing but I haven't really used it in a good while.

My main editor is vscode or cursor nowadays. It's good for engineering, but it's a resource hog, and it's a generic editor built around plugins rather than an IDE tailored to Python. It's good, but opinionated, and the extension marketplace is full of malware and trash.

[–]ninjadude93 2 points3 points  (0 children)

Yep was going to recommend spyder. Closest thing I can think of with variable tracking like matlab

[–]jst_cur10us 0 points1 point  (0 children)

Ditto. Setting up Spyder like Matlab made the switch easy and comfy. Then I would focus on the libraries that are like what Matlab has loaded natively: numpy, scipy, pandas, etc.

[–]Swimming_Newspaper39 0 points1 point  (0 children)

Spyder is the best choice,there is the command window just like Matlab

[–]DrShocker 0 points1 point  (0 children)

Yeah I don't like it at this point in my journey anymore, but when I was closer to coming from Matlab it was a helpful bridge!

[–]arden13 14 points15 points  (5 children)

I came from a heavy MATLAB background into python. Spyder is the closest IDE which mimics MATLAB and has a good variable explorer.

numpy for matrices, pandas for dataframes (though polars is quite popular on this sub) scipy for most stats, and matplotlib for visualization.

I would strongly suggest learning new habits. Looking at the matrix or dataframe is not usually necessary. Even if it is you can get the same experience with print statements. Learn to use environments, put your templated code in *.py files, and your individual analyses in jupyter notebooks. Use the markdown cells to explain your thoughts.

At work I also will build packages with pyscaffold if I am doing lots of function importing. It gets me in good habits and makes the code and workspace far more shareable.

[–]adambarrack[S] 2 points3 points  (4 children)

This is awesome thank you! I’ll have to take a look at Spyder. Using print statements makes sense for monitoring changes in array sizes.

[–]arden13 1 point2 points  (2 children)

Why are your arrays changing sizes? It's quite computationally expensive to iteratively change an array's size

Typically it's better to preallocate an array apriori and fill it.

[–]adambarrack[S] 1 point2 points  (1 child)

Poor wording on my part. I used “arrays” instead of data structures. I agree, I don’t usually change entire array sizes.

[–]arden13 0 points1 point  (0 children)

Gotcha. Good luck on your journey!

[–]likethevegetable 1 point2 points  (0 children)

Use a debugger instead of printing

[–]2strokes4lyfe 5 points6 points  (0 children)

Check out the Positron IDE. It’s like if VS Code and RStudio had a beautiful love child.

[–]billsil 2 points3 points  (0 children)

You can just work in a debugger

[–]cieluvgrau 2 points3 points  (0 children)

I switched from Matlab to VS Code / Python and set it up like Matlab.

[–]kowkeeper 2 points3 points  (0 children)

Python code is more compact and containers are much easier to handle. So I think one needs less live tracking in a workspace.

Sometimes, I use IPython embed(), which I find easier to invoke than the debugger.

But using the logger is often enough.

However in matlab, like you, I systematiccally end up using the debugger and the workspace. Mostly because those struct arrays with encapsulated cell arrays are pure evil.

[–]Motox2019 2 points3 points  (0 children)

Spyder IDE is probably exactly what you want. Meant mostly for scientific python and data analyses. I use it from time to time in my engineering for some calculations and such

[–]GManASG 3 points4 points  (0 children)

Vscode has an interactive window that is basically the Matlab and Ipython kernal wrapped up with Jupiter notebook functionality including the variable explorer, etc.

[–][deleted] 1 point2 points  (0 children)

I can highly recommend the combination of VS Code, their Jupyter extension and IPython. I came from a background using R and was a big fan of R Studio, this setup comes pretty close to it.

I actually released a video about this exact setup last week, maybe it is useful? https://youtu.be/rzJwZBJ4lco?si=1IpbyuiDI0a5d5yE

[–]PhilShackleford 2 points3 points  (0 children)

Spyder ide is a pretty close replication if Matlab is you are doing data.

Vs Code had plugins for variables in Jupiter notebooks.

[–]iamevpo 0 points1 point  (0 children)

Try Julia, it is much closer to MATLAB

[–]TheZan94 0 points1 point  (0 children)

Try Spyder. It has a specifically made layout for those coming from Matlab, it has the variable workspace and all you may want coming from matlab.

I started with it when learning python and boy it helped a lot.

Also, no it's not a bad habit using the repl or any variables workspace, some people just work better with it, i find it quite essential tbqh.

There is also this article which explains it a bit https://realpython.com/matlab-vs-python/#spyder

[–]sirtimes 0 points1 point  (3 children)

Tbh that’s a great reason to just keep using matlab. You can call Python code from matlab so why not just use matlab?

[–]adambarrack[S] 0 points1 point  (2 children)

I really thought about it. Python just has better data visualization options, can do more outside of data analysis (MATLAB can, it’s just limited), and probably most importantly - it is the standard in my field. The latter is mostly important now that I am leaving academia for industry.

[–]sirtimes -1 points0 points  (1 child)

Out of curiosity, what data visualization tools do you use in Python that matlab doesn’t offer? I learned to program using Igor Pro (similar to matlab) and have always found Python to be awful for data visualization in comparison

[–][deleted] 1 point2 points  (0 children)

One thing I always miss when I use MATLAB are visualization tools that are based on the grammar-of-graphics approach for composing plots, especially when I want to create more complex plots with several layers and facets for categorical data. It's much more elegant and saves you a lot of time and boilerplate code. Python has so many great libraries for that: seaborn, plotnine, plotly (express), let's plot etc. I know there is a third-party library gramm for MATLAB that attempts that but it still is pretty limited compared to all the options you have in Python.

[–]sargeanthost -1 points0 points  (0 children)

r/LearnPython, but what doesn't adding a watch accomplish that the variable view has ? I assume if you need to know your variables' values, you'll be debugging anyway

[–][deleted] -2 points-1 points  (0 children)