-
-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow using maturin develop outside of virtualenv #284
Comments
When would this be required? I generally advise against installing anything but standalone cli tools into the global environment, and even that breaks easily. I wouldn't want to encourage using the user/system site packages with maturin, especially since it's still simple enough to use |
I submitted this bug report for my coworker who doesn't have a github account. Here's his response:
So maybe adding documentation to the error message on how to install using |
setuptools also has
This would build the |
I've updated the message to make the options clearer. I'm however not interested in supporting anything that could break the user's global environment. |
I'm using docker for development so I don't really care about using venv or something else. We still need a For now, I am doing |
Is your dev workflow to
It actually always does a release build, PEP 517 has no way to communicate whether you want dev or prod (https://discuss.python.org/t/pep-517-debug-vs-release-builds/1924) |
There is no reason to have a virtual env with just one env. It's the dev docker container and contains everything needed for that project. You can revert to use virutalenv inside docker but
I wouldn't force people to use virtualenv if features do not directly depend on venv specific internals. It's just a python env. Maybe remove the venv guard and print a warning without a |
I am trying to run maturin on All I want is for maturin to do its thing and put the dev binary in the python_src folder See broken repl here: https://replit.com/@thehappycheese/Megamerge#pyproject.toml ... hopefully this link takes you to the explorer/editor view and not the stupid preview screen that repl.it sometimes shows when you are not logged in. |
you can still |
Not true. Try it. repl.it prevents the installation of the To be fair, its more of a problem with repl.it than with maturin. I understand why maturin wants to be inside a venv. But still maturin seems at least 10% at fault for being so inflexible. |
I would like this feature for use within a CI job. We have a docker image that is used for python CI builds. It is based on something fairly old and was providing pip 18.x. So I updated the Dockerfile to update pip to the current version, which worked fine. I then started trying to use it for a mixed rust/python project. Since I am in a single use container, there is no problem with installing into the global environment. So I tried
which is apparently not the correct way to install the maturin wheel locally. After several more tries, I gave up on So I created a venv, activated it and ran the commands inside the venv. Which then failed, because the venv was using pip 18, not the updated pip from the global environment. Eventually, I got it working by creating the venv, activating the venv, updating pip, and then doing the stuff I actually wanted to do. Which is a lot of extra code to understand when looking at the CI config file, plus extra work the CI server is doing, making the job take longer. And if there is some other tool in the global workspace that was also updated, I'll need to update the in the venv as well. So it is a lot harder to understand and maintain, and slower to run, that being able to do
|
i don't know you're exact setup, but there's nothing that
if you do |
I just want to add one thing to this discussion:
This is relevant, as for local development an editable install is needed, as well as for some other edge cases like running pytest-cov in your CI pipeline. Requiring a virtual environment is just needlessly restrictive. The responsibility should lie with the developer to manage their environments correctly. Now Unless there is a technical reason |
When would you do local development in your global environment? Wouldn't this mean that all of your projects share one environment, potentially overwriting each other, and also interfering with globally
How does this impact pyenv-virtualenv, i'd expect a tool called pyenv-virtualenv to create virtualenvs? And what are those not standard venv workflows? i do understand that with docker using the global environment is not a problem, but for deployment cases you should use separate build stages for build and deploy anyway, and also in containers there can be os installed python tools and debugging the global environment is a nightmare. |
I'm using |
You probably should not, but that also should not be the concern of maturin. Also there are some packages which simply dont have any dependencies. In this case a venv is simply an overhead. |
One of the key motivations for maturin is that it prevents you from shooting yourself in the foot. It will make you go the extra mile to prevent you from seemingly easy solutions that end up breaking things. |
For reference (this is on WSL2): $ pyenv virtualenv maturin-check
$ pyenv shell maturin-check
$ pip install maturin
$ maturin develop
💥 maturin failed
Caused by: You need to be inside a virtualenv or conda environment to use develop (neither VIRTUAL_ENV nor CONDA_PREFIX are set). See https://virtualenv.pypa.io/en/latest/index.html on how to use virtualenv or use `maturin build` and `pip install <path/to/wheel>` instead.
$ echo $VIRTUAL_ENV # empty - pyenv does not set this environment variable
|
Just as a feedback from me as one of many users of this great tool: |
Let's step away from hypotheticals for a moment and consider a very common use case: calculating test coverage in a CI workflow. In this case:
In fact, working with virtual environments in Github Actions is a big pain as you need to find a way to activate it and keep that state between multiple steps. You can do it by adding it to the GITHUB_PATH, but maturin does not recognize this, and I still have to call See an example here for a workflow where you see this in action. This could be much simpler if a virtual environment was not enforced. As a 'middle ground', I like the suggestion of adding a |
@stinodego Have you tried My ~ ❯
pyenv shell test
~ via 🐍 v3.9.11 (test) ❯
env | grep VIRTUAL_ENV
PYENV_VIRTUAL_ENV=/Users/messense/.pyenv/versions/3.9.11/envs/test
VIRTUAL_ENV=/Users/messense/.pyenv/versions/3.9.11/envs/test |
I'm hitting the same problem. Why does this thing enforce using venvs? |
FYI, you can fake a virtualenv by setting the export VIRTUAL_ENV=$(python3 -c 'import sys; print(sys.base_prefix)')
maturin develop or simply: env VIRTUAL_ENV=$(python3 -c 'import sys; print(sys.base_prefix)') maturin develop |
BTW, there is a new PEP 704 pull request today that require virtual environments by default for installers (like pip). |
I wonder if
Unfortunately with maturin this doesn't work, it requires the venv to be activated to do something useful. |
I think it's possible, we can read But this can be confusing when user installs maturin using |
@mitsuhiko Would it work if did something similar to the PEP 704 suggestion where we check if a virtualenv |
There is no necessary relationship between the current working directory and the environment that is used to run maturin. There is no reason why a virtual environment should necessarily be found in any parent of CWD and there is also no reason why it should be named $ ../envs/3.8/bin/maturin develop The way that I use pyenv-virtualenv is to create environments like: $ cd myproject
$ pyenv virtualenv myproject-py311.git
$ pyenv local myproject-py311.git These virtual environments are not located in the current directory but rather in $ maturin develop
💥 maturin failed
Caused by: Couldn't find a virtualenv or conda environment, but you need one to use this command. For maturin to find your virtualenv you need to either set VIRTUAL_ENV (through activate), set CONDA_PREFIX (through conda activate) or have a virtualenv called .venv in the current or any parent folder. See https://virtualenv.pypa.io/en/latest/index.html on how to use virtualenv or use `maturin build` and `pip install <path/to/wheel>` instead. The method used by maturin to check if it is being run from a virtual environment fails when the virtual environment is used by pyenv without activation because the environment variable is not set in that case. The way to find if maturin is running in a virtual environment created by either
The
In principle
It might be confusing but apart from a special case check for whether or not |
We do look for pyvenv.cfg for
No, poetry will look for - in that order - an activated venv, .venv (with
Given the popularity of pyenv, it might make sense to support |
Why not? That's exactly how I tell $ mkdir envs
$ python -m venv envs/3.8
$ envs/3.8/bin/pip install maturin
$ envs/3.8/bin/maturin new demo
$ envs/3.8/bin/pip install ./demo
$ cd demo/
$ ../envs/3.8/bin/maturin develop
💥 maturin failed
Caused by: Couldn't find a virtualenv or conda environment... Here |
I got this error: Fixed it by running My machine has both conda & Poetry installed. Just posting here to help others overcome this error. |
Hello. |
I am interested in your discussion. |
I want to know it's possible to use maturin build without virtual env. |
there are still some case, for example, it make no sense to setup a virtualenv in ci. even PEP 704 allow tools to provide a tool to disable this requirement |
Recently lots of newer operating systems with newer python/pip version are requered to use My feeling is that it's easier and consisent to just always use a venv. |
https://github.com/PyO3/maturin-action/blob/main/.github/workflows/test.yml#L38 Fixes the 0.14.2 and 0.13.0 macOS Python packaging failures. Notice that all these jobs use macOS 14.7. - 0.14.2: https://github.com/spiraldb/vortex/actions/runs/11821278964/job/32936900282 - 0.13.0: https://github.com/spiraldb/vortex/actions/runs/11630848959/job/32391375552 Neither 0.14.0 nor 0.14.1 failed before macOS build. 0.12.0 was the last passing one. It used macOS 14.6: - 0.12.0 https://github.com/spiraldb/vortex/actions/runs/11166071447/job/31039891955 See also: - PyO3/maturin#284 - PyO3/maturin-action#291
Given that the motivation of requiring virtualenvs is to avoid breaking system packages, but the ecosystem has now broadly implemented Externally Managed Environments as per the above breakages, is it time to follow suit in maturin? i.e. we could downgrade the requirement from "you need a virtualenv" to "you cannot use |
I think "you cannot use develop in externally managed environments" make more sense. And another workaround here is, skip maturin and call cargo directly, since pyd is just a dll and cargo doesn't care if there is a python venv. cargo build
cp target/debug/lib.dll lib/__lib.pyd
# or
cp target/debug/lib.so lib/__lib.so this is almost the same behavoir as |
We can support using the global environment, which is e.g. used in some docker workflows. We should not install into the user-wise site packages, as they aren't isolated from other projects. |
There might be good reasons for not installing into the user site-packages but I don't think maturin should try to detect this for anything other than printing out a warning. If nothing else then at least there are always going to be cases where the detection logic gets it wrong as in pyenv and other examples above. It would be better if maturin just installs the package without trying to guess what environment to use and without trying to judge whether the target environment is reasonable. Unless there is some technical limitation that prevents |
there may be someone install maturin with pipx |
This seems like something that would be useful to allow, perhaps requiring a
--force-develop
flag of some sort if retaining the current error message seems useful to direct beginners to using virtualenv.The text was updated successfully, but these errors were encountered: