Here is a simple Cython package:
foo/
__init__.py # Contains: from . import foo
foo.pyx
I use waf (I know pyximport or setup.py can be used too) to build the Python extension from foo.pyx:
foo/
__init__.py # Contains: from . import foo
foo.pyx
build/
foo/
foo.cpython-35m-x86_64-linux-gnu.so
I would like to import the foo package without installing it (development mode).
If the Python extension would be next to __init___ like this:
foo/
__init__.py # Contains: from . import foo
foo.cpython-35m-x86_64-linux-gnu.so
it would work, but __init__.py is in the the source directory while the .so file is in the build directory.
I would like to avoid copying .so files in source directory.
A solution solution would be to copy (with waf) foo/__init__.py in build/foo/__init__.py, and import the foo package in build/.
Is there other alternatives?
Source code is here.
Related
My folder structure is like this
cloud_fn_dir
cf1_dir
main.py
util.py
requirements.txt
test_main_cf1.py
cf2_dir
main.py
requirements.txt
test_main_cf2.py
cf3_dir
main.py
requirements.txt
test_main_cf3.py
I am executing unit tests and generating coverage report using command - pytest -v --cov=main --cov-report=html
If I am executing the command from inside the Cloud function folders i.e. cf1_dir or cf2_dir folders then the pytest command works as expected and executes the unit tests and generates reports inside that folder.
But I wish to execute all the unit tests at once and generate a single report and hence I tried to execute the same command from outermost folder i.e. cloud_fn_dir and encountered Import Error where the test_main_cf3.py file is trying to import Class of cf1_dir main.py file.
Each of the test file is importing it's respective main.py file in it and creates an object and calls the methods to test. So when I execute the pytest command it is making the last test file i.e. test_main_cf3.py to import main of cf1_dir main.py and execute the methods. Pytest is trying to import the first encountered main.py class
How do I resolve this import error ?
I have a file that I want to "cythonize", myfile.pyx. I also have a helper file, myhelper.pxi.
myfile.pyx contains within it the following line:
include 'myhelper.pxi'
If the helper file was not needed, I think setup.py would look like this:
from distutils.core import setup
from Cython.Build import cythonize
import numpy
setup(
ext_modules = cythonize("myfile.pyx")
)
Can you tell me how to properly incorporate the helper file into the setup.py code?
It's fine as is - setup.py only needs to know about "myfile.pyx". It doesn't need to know about the internal details of "myfile.pyx" (i.e. what files it textually includes).
This does mean that setup.py won't recompile things when you've only changed "myhelper.pxi" because it doesn't know about the dependency. There isn't really a good way round that. Use --force on the command line to make setup rebuild everything if that's a problem.
The repo works on my machine but not on gcloud.
Structure of repo (on Google Cloud Source Repo):
project/
├── localdep.py
└── mylocalpackage/
└── main.py
In main.py:
import localdep
Yet I receive the following error:
ModuleNotFoundError: No module named 'localdep'
What am I doing wrong?! There is no problem running this on Pycharm on my machine, yet when I push to gcloud there is...
The proper structure should be to have the main.py at the top level and the other files on the nested folders. You can take a look into this, which talks about Structuring Your Project.
Just in addition, I have tried with both from ..localdep import * and from ..package import localdep, and other like from ... import localdep, but either I receive ImportError: attempted relative import with no known parent package, or ValueError: attempted relative import beyond top-level package.
It worth to rethink your project structure.
I have Win 7 machine and TCL installed from
downloads.activestate.com/ActiveTCL/releases/8.6.4.1/ActiveTcl8.6.4.1.299124-win32-x86_64-threaded.exe
I am using TCL package fileutil successfully , as:
proc foo{} {
# some code
package require fileutil
# able to use ::fileutil::updateInPlace in code
}
foo
This is done by script at
C:/SVN/code/changeFile.tcl
Now, I use same code as part of bigger script as
proc foo{} {
# some code
package require fileutil
# some code using the package
}
# more code
cd "C:/SVN/code"
foo
#more code
cd "C:/Program Files (x86)/Target Compiler Technologies/adsp2-12R2/designs/adsp2/ISS"
This is part of script called audio_sim.tcl ,and is invoked by following commands on shell
cd "C:/Program Files (x86)/Target Compiler
Technologies/adsp2-12R2/designs/adsp2/ISS" adsp2_ia.exe -T -t
"C:/SVN/code/audio_sim.tcl"
This now gives error:
can't find package fileutil
Why it complains now when it is similar to what I did in the first case?
As slebetman wrote, adsp2_ia.exe probably can't find the ActiveTcl library files, but you can import the package yourself. In my 8.6.1 installation, the file is at C:\Tcl\lib\teapot\package\tcl\teapot\tcl8\8.2\fileutil-1.14.8.tm. Your location or version number may be different, but note that you are looking for a .tm file. It will not be in any directory named fileutil, those are for related packages.
(Another slebetman pointer:) It may be possible to make the module visible by calling ::tcl::tm::path add with the path as argument.
If not, use source to import the code. Make the call in the global scope, outside of any procedure.
Then you should be able to call package require fileutil.
Documentation: package, source, tm
https://scipher.wordpress.com/2010/05/10/setting-your-pythonpath-environment-variable-linuxunixosx/#comment-219
I did this tutorial to set up my pythonpath variable in my Linux computer,
the odd thing is that I can only import my modules from /home
I did cd /home and vi .bash_profile, did the changes pointing directly to my folder with my modules, such
PATH=$PATH:$HOME/bin:"/share/my_modules"
PYTHONPATH="$PYTHONPATH:/share/my_modules"
export PATH
export PYTHONPATH
and save the file.
from there I can do python and import my modules,
but if I go to any other directory and I try to import my modules, it fail =(.
if I do
import sys
sys.path
my folder /share/my_modules is not there =( but do show in the terminal from /home.
do I need to set up a .bash_profile file in each folder? I am missing something?
thanks guys.
https://help.ubuntu.com/community/EnvironmentVariables
reading this document, explains that are 2 ways to set it up,
one is modifying the /etc/environment file.
or making an sh file under /etc/profile.d/*.sh
and putting the variables like
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0
export PATH=$PATH:$JAVA_HOME/bin
that way every time a terminal is open will run that, export those variables and will work.