Integrating PyCharm with Abaqus - python

I'm using PyCharm Community V2021.1.3 and I would like to integrate Abaqus CAE (2021) with PyCharm so that I can write/debug/run scripts for Abaqus.
Currently I write code in PyCharm/Sublime or some other editor and then run the script through either the command line function or within CAE. The real issue that I have is debugging the script. Abaqus comes with it's own IDE (Abaqus PDE) but lets be honest.... there's A LOT of room for improvement and it absolutely sucks for debugging. In the past I have ended up copying/pasting sections of code directly into CAE kernal commands just to try and pinpoint where issues might be. Far from ideal.
My PyCharm installation is using a Python 3.5 interpreter. I try to keep my projects segregated as I often have to switch between various packages and versions depending on what I'm working on. I would ideally like to create a new virtual environment that hosts the Abaqus version of Python (2.7.3) and packages associated with that version of Python. Generally I use Conda to create/maintain virtual environments however, in this case, Abaqus has installed the relevant version of Python and several packages as part of the Abaqus installation procedure. Is it necessary for me to create a new virtual environment if the Python version and packages I need are already installed locally? If I point the interpreter directly to the Abaqus installed Python version and then screw up later is that going to be a major fix? Normally if something goes wrong in a virtual environment (mixed up package requirements or that) I just delete the environment and set up a fresh one...
I'm fairly new to PyCharm (<6 months) and so I'm unsure of how best to integrate these two pieces of software (PyCharm and Abaqus) without completely messing up my Abaqus installation. This similar question: How integrate Abaqus python libraries into a project hosted in PyCharm suggests adding a new system path (PYTHONPATH) to system variables. Restarting PyCharm and then pointing the Pycharm interpreter to the system interpreter. That kind of makes sense to me but I'm not sure whether that will effect my existing virtual environments for Python 3.5? The whole point of having virtual environments is that you don't run into issues with package compatibility so I think it should be OK? If I set up a new virtual environment for Python 2.7.3 (same as the abaqus installation) and get a range of packages associated with that python version then I'll still be lacking some of the Abaqus specific packages required for checking types etc. That's why the previous post has probably recommended pointing the interpreter directly to the Abaqus installation. Is there a way to clone that version of Python and packages to a new conda virtual? Any help, tips, relevant posts etc. would be greatly appreciated.

It is impossible for us to debug the abaqus/python script since we don't have the access to the abaqus/python source code. But there is an alternative way to make things better, if type hints of the abaqus/python functions are provided, it is much more easier to debug the script. Fortunately, abaqus provides the documentation for almost all of the python functions in its website, based in the online documentation, I restructured the abaqus/python classes to provide type hints for the abaqus/python functions.
According to this consideration, I have developed a package named "pyabaqus" to provide type hints for abaqus/python scripting and submit the script file to abaqus kernel, you can check it in pyabaqus or github.com/Haiiliin/pyabaqus, hopes it helps you.

Related

PyCharm Virtual Environment Setup [duplicate]

This question already has answers here:
How to activate conda environment from powershell?
(8 answers)
Closed last year.
I'm trying to get on with Python coding rather than fiddling about with settings getting in the way of development. Alas, it is not meant to be.
1 - I've installed Python 3.9 in Windows 10 from the Windows Store (running python in a powershell and instructions therein).
2 - I'm using PyCharm IDE.
I am very familiar with JetBrains products and building php projects. The transition to Python is not as straightforward. When I setup a new project and want to run code I need to set my configuration for the virtual environment.
I range from not being able to run any code through to perfect success with a lack of being able to import libraries in between.
In my toolkit is:
a) Edit Configuation - selecting a python interpreter. This never seems to make any difference no matter which one I choose. I only have options that are the right version but seemingly python.exe files in the project, in my Windows directory and all over the place.
b) Settings>PythonInterpreter>VirtualEnvironment>ExisitngLocation
When I get it to work it's usually the python.exe in the Windows directory that pip installs everything in. Selecting that interpreter then locates all the packages I have installed and I can import all the libraries I want.
I would like to (i) understand why I have so many options (don't I just use python.exe because I've installed it somewhere) to pick a multitude of python.exe everytime I build a new project. I have missed this aspect of Python.
I would like to (ii) understand how to get a project to reference the libraries I have installed on my machine such that I can access them properly in my project and spend less time trying to wire everything up and more time actually building the project out.
I had a similar issue initially.
My "solution" was to delete python from the Windows Store, install Anaconda and then follow these steps from a SO answer for enabling PowerShell to run python with conda
Details in creating projects with PyCharm can be found here (a webpage on Anaconda).
Then PyCharm just works... like a charm.

Installing a second python environment I’m mac

I’m trying to figure out how to install a second python environment alongside anaconda.
On windows I can just install python in a different folder stand reference the desired python environment using env variables. I’d like to do the same on Mac.
A virtual env won’t do the trick as it does not copy the standard library and other things. It needs to be a complete stand alone environment. I guess I could compile it, but is there an easier way?
Thank you very much for any input.
You can do that using pyenv.
It allows you to have several python versions, and even different distributions.
It works, mostly on user space. So, no additional requirements are needed (apart from compilation tools)

Jupyter Notebook cannot find certain modules

As part of a web scraping class I've been instructed to download a few modules from the command terminal (requests, bs4, lxml). These have seemingly been successfully downloaded to my computer, yet my Jupyter Notebook AND PyCharm virtual environment cannot find them.
I am a beginner so I'm sure there are some big things I'm missing, any help would be appreciated.
How did you install Jupyter?
Wich package manager are you using? (eg. what did you type to install the packages?)
Wich modules can it find and which not?
Usually you want to make sure your modules are available in the environment you are using. ( Enviornments are like "versions" of python. You could run multiple versions like 3.7 and 3.9 on your Computer but also also different builds from one python version.)
Pycharm builds its own environment. Make sure you use the enivorment you installed your packages to in Pycharm. Pycharm allows you to modify and create new environments very easily
For PyCharm it might be useful to check out their help page.
I figure this could help: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#add_new_project_interpreter
The interpreter is basicly the a customized version of python. Pycharm keeps track of the modules you need for every project. So you want to create/select an interpreter which has the packages you have installed.
hope it helps
cheers

What are the bare minimum files/libraries required by Python to run?

I am new to Python having come from a proprietary compiled language (Xojo) that produces self-contained executables.
I understand that Python is an interpreted language. I understand that it requires an interpreter (let’s stick with CPython) and presumably it requires a number of accessory frameworks/C libraries in order to run. What I don’t understand is why is it so hard to create a folder containing the interpreter and all required files and libraries and simply bundle these up with my script to distribute.
I have discovered that there are a bunch of tools that attempt to do this (py2app, cx_freeze, etc) but many of them seem either broken, not maintained or really buggy.
I guess my question is: is there any documentation that describes the exact things I need to bundle with a “Hello World” script to get it running? This seems to be a really straightforward problem to solve but it hasn’t been (which suggests that it is far more complex than I appreciate).
My understanding is that PyInstaller works fine for making a single exe for distribution. But barring packaging tools like that, in general, there isn't an obvious "bare minimum"; the modules don't have documented dependencies, so it's usually best to ship the whole standard library.
Typically, if you need a redistributable version, you use the embedded Python zip redistributable, shipping Python alongside your main application.
The exact list of files/libraries depends on how the python interpreter is built. In windows for example, you can obtain CPython binaries built from Visual Studio, Cygwin and Mingw-w64. They have different dependency of cause. In Linux distributions, python is normally installed by default.
Below is the list of .dll and .exe files that you can find in the official CPython release for windows.
libcrypto-1_1-x64.dll python.exe python37.dll sqlite3.dll
libssl-1_1-x64.dll pythonw.exe python3.dll vcruntime140.dll
The total size of this ZIP file release is only 6.7 MB. So it would be easy to bundle it in your main executable. You can use whatever bundler at hand, not necessary those designed for python. Quoting from the documentation here:
extracting the embedded distribution to a subdirectory of the application installation is sufficient to provide a loadable Python interpreter.
I feel the absolute best way to experience Python for beginners in thonny and an esp32.
A very good way to get started with python is to use Anaconda https://www.anaconda.com/distribution/#download-section - this distribution contains the CPython interpreter and the most commonly used packages. For quite a while you will get along without installing more packages.
To be able to make a simple distributable piece of code just include a requirements.txt along with your code which should list down the packages (and versions) you are using in your code.
More on that here : https://www.idiotinside.com/2015/05/10/python-auto-generate-requirements-txt/
pip freeze generates a superset of all packages in your running environment so you would ideally go with the second smarter option in the link : pipreqs
So, in short along with your code just an additional requirements.txt should be fine using which people can install all required packages as
pip install -r requirements.txt
and they are good to go to run your code.
For advanced scenarios you might want to look up creating virtual environments using conda.
What is a conda environment?
https://docs.conda.io/projects/conda/en/latest/user-guide/concepts.html#conda-environments
How to create/manage a conda environment
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
All the best in your Python journey!

Installing Multiple Python Distributions, Windows

I am using PythonXY (2.7, 32-bit) and the official Python (2.7, 32-bit).
Normally it is recommended to install according to python version, example C:\python27. But since they are both python27, can I arbitrarily change the base name (example C:\pythonxy27)?
When using python extras like pylauncher, or when utilizing the setuptools user-site, will they automatically recognize my custom installation sites (they will easily differentiate C:\python27 and C:\python33), or will both installations compete for the python27 namespace. (specifically when installing 3rd party packages to user-site, which normally locates as such \APPDATA\Python\PythonVer)
As far as setuptools/distribute are concerned, the python installer will handle custom locations for you. As long as you don't move that directory, all should be fine.
As for Pylauncher:
Things are not quite so clean. Pylauncher has simple configuration/call-parameters (for shebang lines in particular), that can handle version/platform selection quite well (2.7 vs 3.3, and 32bit vs 64bit).
As for the scenario in question (two different deployments where both are based on 32bit Python 2.7), pylauncher will attempt to guess which installation you wanted. If it is picking the wrong installation, there is some debugging information you can review to tune pylauncher's selection.
If an environment variable PYLAUNCH_DEBUG is set (to any value), the
launcher will print diagnostic information
It does not seem like there is a portable way to configure this, and will have to be done per-system (once you have your installations configured, YOU CAN set an alias that will be recognized on the shebang line)
Virtualenv and friends
I have also found (after struggling with pylauncher focused solutions), virtualenv addresses many of the deployment isolation hurdles. At the time of posting, working with virtualenv was not nearly as intuitive (on Windows) as compared to a linux shell environment. But I have discovered support packages like virtualenvwrapper which handle a lot of the ugly batch file interfaces very nicely.
Final Notes
Originally, I was also handling python globally with admin accounts. Forcing myself to stay within my user home directory (C:/Users/username), utilizing python user-site configurations, and making optimum use of ipython: have all given me a much better interactive command-line experience.

Categories