I have a really weird problem. I'm developing a Pyramid project and it seems like non-existing module is found when I run pserve.
__init__.py of my main module:
...
# This works !!! db/models directory does not even exists
from db.models import Base
# Also works - db/model exists
from db.model import Base
...
I even tried to recreate my virtual environment and it still finds it.
Any ideas?
From the comments it appears this was solved and it was leftover *.pyc files. This problem can come up a lot if you're moving between branches or if you find yourself frequently renaming/deleting files.
$ find mydir -name "*.pyc" -exec rm {} \; will recursively find all *.pyc files in the "mydir" directory (replace mydir with your directory name of course) and delete them. $ find . -name "*.pyc" -exec rm {} \; for your current working directory.
If you're using git for your project, add this script to your post-checkout hook to prevent differences between branches from getting in your way.
$ echo "find src -name "*.pyc" -exec rm {} \;" >> .git/hooks/post-checkout
Related
Oddly enough I'm able to run my flutter applications, but I'd like to upgrade. However since I've updated to MacOS Ventura Flutter can't be found anymore...
output of echo $PATH:
/Users/me/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/flutter/bin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
What the top of my .zshrc file looks like:
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
Any help and info is greatly appreciated
P.S dart and python also cannot be found. But they're not in my path so guess that makes sense
If you normally start flutter by typing:
Flutter
you can search in /usr and /opt for a file (rather than a directory) that is executable (i.e. a program) and called Flutter like this:
find /usr /opt -name "Flutter" -type f -perm +111
Then, if/when you find it, add the name of the directory that contains Flutter to your PATH. So if it finds:
/opt/homebrew/bin/Flutter
you would do:
export PATH=$PATH:/opt/homebrew/bin
If you don't find it in /usr or /opt, you will need to perform a more time-consuming search across the whole filesystem and also suppress error messages:
find / -name "Flutter" -type f -perm +111 2> /dev/null
Im trying to write a script:
env PYTHONPATH=$PYTHONPATH: $Dir/scripts find * -name ‘*.py' -exec pylint (} \\; | grep . && exit 1
The code is finding all scripts in the root directory instead of using the environmental variables I set. Any help on writing this code to only look for files in the directory I set as a value in PYTHONPATH.
env PYTHONPATH=$PYTHONPATH: $Dir/scripts isn't doing what you think it's doing. Including $PYTHONPATH includes the former value of PYTHONPATH, meaning whatever you have it already set to or a blank default. The space in your variable also makes it invalid, and instead interprets the $Dir/scripts as a new command. It looks like what you want would be env PYTHONPATH=$Dir/scripts — but there's actually an easier way.
If you have __init__.py files in your directory, you can just do pylint ./some-directory. If you don't, you can use xargs: find . -type f -name "*.py" | xargs pylint. If you wanted to pass the directory instead of have it coded to . (your current calling directory) you could do that too:
# set directory to first argument
dir="$1"
# check if "dir" was actually provided, if not, set to `.`
if [ -z "$dir" ]; then dir=.; fi
find "$dir" -type f -name "*.py" | xargs pylint
You could save that in a script or function and then call it either with a directory (like run-pylint-on-everything.sh ~/foo/bar, or not, in which case it would run starting from your current shell location.
There’s no space between the PYTHONPATH value, it was a typo mistake, I want to run the command on a CLI instead of a script.
I am using:
mkdir -p build/python/lib/python3.6/site-packages
pipenv run pip install -r requirements.txt --target build/python/lib/python3.6/site-packages
to create a directory build with everything I need for my python project but I also need to save as much space as possible.
What can I safely remove in order to save space?
Maybe can I do find build -type d -iname "*.dist-info" -exec rm -R {} \; ?
Can I remove *.py if I leave *.pyc?
Thanks
Perhaps platform specific *.exe files, if your project doesn't need to run on Windows:
How to prevent *.exe ...
Delete *.pyc (byte-compiled files), with an impact to load-time: 100% supported, unlike your trick of the reverse: retain just *.pyc (and delete most *.py sources) in some python versions; not safe IMHO but never tried it.
I have a file in my directory called foo.py that contains Python code. How do I pipe the file to Python in the terminal so that Python will run it? Entering this into the terminal doesn't work:
find -name foo.py -print | python
Use -exec parameter to find and execute all the founded .py files.
find -name '*.py' -exec python {} \;
And for a single file, you may use
find -name 'foo.py' -exec python {} \;
Note that this would search for the name foo.py in the current directory as well as the subdirectories.
I have a Django project and I'm working on Pylinting my way through it.
I have a couple situations where I'd like to be able to recursively find all files with a given name and pylint them differently (using different options). For example, I'd like to set different options for pylinting urls.py and admin.py
The following works for 1 directory..
pylint ./project_name/*/urls.py
But I'd like to make that * recursive... so that it drills into sub directories.
Any way to achieve that?
Update
I'd also like them all to run as a single pylint output, not sequentially
Depending on your operating system, you could use:
find project_name -name urls.py | xargs pylint
Try with find:
find ./project_name/ -name "urls.py" -exec pylint '{}' \;
If you want to run multiple files in a single call to pylint:
find ./project_name/ -name "urls.py" -exec pylint '{}' +
Get all python files (recursive)
Pass them all at once to pylint (from answer by Robin)
Show output in console and put it in a file
find . -name "*.py" -print0 | xargs -0 pylint 2>&1 | tee err_pylint.rst~