Unable to use packages (pip) in virtual environment -VS Code - python

Every-time I create a new virtual environment, I cannot use pip from it. I know that I managed to solve this once, but I dont know how. It just happened.
So here is how I go about creating a venv:
I create a new virtual environment from the VS Code terminal inside my projects folder using python3 -m venv venv_x.
I get the pop-up asking if I want to use it and I click yes. It also gets displayed correctly.
But when I try to run pip using python3 pip or python pip I get /usr/local/bin/python3: can't open file 'pip': [Errno 2] No such file or directory.
Running which pip gives no putput.
My pyvenv.cfg inside venv_x/pyvenv.cfg :
home = /usr/local/bin
include-system-site-packages = false
version = 3.8.6
What am i doing wrong? It cant be that hard. So I am probably forgetting something obvious.
Every help is greatly appreciated!
Edit: Maybe showing the contents of the venv can help.
But after executing a python script VS Code asks me to install my code formatter black, which after accepted, gets installed by the IDE like this:
`.../dev/test/venv_x/bin/python" /Users/chris/.vscode/extensions/ms-python.python-2021.3.680753044/pythonFiles/pyvsc-run-isolated.py pip install -U black'
The venv packages folder contents gets updated accordingly and black works.

Using only pip3solved it.
Not using python pipor python3 pip or python3 pip3.
I find that quite weird.

Related

Problem running auto py to exe from terminal [duplicate]

I have python 3.9 I used the command 'pip install auto-py-to-exe' and it downloaded but when I tried to using the command 'auto-py-to-exe' the program just said " 'auto-py-to-exe' is not recognized as an internal or external command, operable program or batch file.". I have the latest version of PIP and I also have PATH. What can I do to fix this?
This works on VSCode:
python -m auto_py_to_exe
If I install "auto-py-to-exe" using following command, as described in this link as well as from the comment from Justin Ezequiel (above):
python -m pip install auto-py-to-exe
I am able to run it (in Windows 10) using following command:
python -m auto_py_to_exe
This gave me quite a bit of trouble, as none of the above solutions worked for me. Spent lots of time trying to figure out what I should be adding to PATH with no success.
My issue stemmed from (I think) the fact that I have been using python downloaded from the windows store, which uses a different location to store python in.
With the manual install of python (https://www.python.org) you can specify where python is downloaded and automatically add that location to path.
Steps I took to solve the problem:
Uninstall all versions of python downloaded from the windows store via settings (settings > apps > python > uninstall)
Uninstall all version of python via the control panel (control panel > add or remove programs > python x.x.x > uninstall)
Uninstall auto-py-to-exe (pip uninstall auto-py-to-exe) in case it didnt do that automatically
Install python from python.org. (auto-py-to-exe is not supported in versions greater than 3.10 as of 1/23/2023). So I installed Python 3.10
The settings which were successful for me were:
Custom installation,
check install python for all users,
check add to path,
input 'C:\Python310' (with the respective version number) for install location,
install
Check new python version has been installed python --version
Check pip is installed pip --version
Install auto-py-to-exe pip install auto-py-to-exe
When auto-py-to-exe finishes installing, scroll up through the install info and make sure there are no warnings that state there is a location not found in PATH. If there are, you'll have to do some other research on adding those locations to PATH appropriately (since I don't think I was doing that right).
Assuming no PATH warnings,
9. Run auto-py-to-exe
First you need to type in the terminal (not Python):
auto-py-to-exe
If you are currently in python use exit() to exit then try the above code.
It Depends on in which environment you have installed
Make sure to replace {User} with your user
In Conda Enviournment go to below location Manually
C:\Users\{User}\anaconda3\Scripts\auto-py-to-exe.exe
In Pip, Environment go to the location below
C:\Users\{User}\AppData\Local\Programs\Python\Python37-32\Scripts\auto-py-to-exe.exe
or you can add this path to your environment variable as well for accessing these from anywhere
First check you installed it
pip install auto-py-to-exe
then restart your vscode and check another time.
If still an error, check it in CMD.
As suggested above use:
pip show --files auto-py-to-exe to find out in what directory pip has
installed the scripts. Double check the directory is in %PATH%
This will show you where the installer has placed the binary files. I then changed to that directory which circumvents any path issue. I tried to run the files and found :
OSError: [WinError 1920] The file cannot be accessed by the system: 'C:\\Users\\aaaa\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\python.exe'
PS C:\users\aaaa\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\Scripts>
In my case, although I haven't worked out how to fix it yet... It would seem to be trying to refer to an incorrect Python executable, the files in that directory are all 0 length. Unfortunately the "python -m" suggestion didn't work for me, so it's back to the drawing board. Hope that helps you confirm if it's the right solution to chase down.
You need to make sure you have typed cd C:\Users\your_user_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts as a separate command, and then auto-py-to-exe with python 3. Check in file explorer to make sure your path is correct if the cd fails.

installation problem with epftoolbox in python

I have absolute no further idea, how i could manage the installation of the epftoolbox in python. I have tried the steps from https://epftoolbox.readthedocs.io/en/latest/modules/started.html in various ways and directions, but it still doesn't work and i get the following error when running the file:
ModuleNotFoundError: No module named 'epftoolbox.evaluation'
Can anyone suggest a step by step video or something like that, where the installation is showed for 'dummies'?
Any help would be veeeeery appreciated!
PS: I'm working with pycharm
Since you're working with pycharm first create a new project with a virtual environment and open the terminal and type the following clone statement : git clone https://github.com/jeslago/epftoolbox.git
then move to the cloned directory by typing this command:
cd epftoolbox
once your'e inside this directory run your pip install command:
pip install .
you should be able to work with the library here.
since you already created the virtual environment..
Hope it solved your problem.

Transitioning from CS50 IDE to VS Code (Import module does not work)

I recently finished with PSET9 and wanted to transition from CS50 IDE to VS Code for the Final Project. Problem is I don't know what exactly I need to set up to make it all work. I guessed that I just need to import the CS50 library, which I then did following me checking out their GitHub. I did as instructed pip3 install cs50. However, even though various files were installed, my application.py is still saying that it can't find any modules, see screenshot. Why is that? What do I need to do?
Also what might I still be missing after having resolved this? Do I still need to do something to fully have the CS50 IDE essentially running on the VS Code (server, databases, etc)?
VS Code screenshot
I think you need to create virtual environment for that and then activate it.
Create virtual environment in command line Windows
go to you root app folder.
python3 -m venv env (type this command in terminal)
for activate env type this in windows (env\scripts\activate)
for apple and linux type this in terminal) source env/bin/activate
then use pip install
First thing to do is just make sure you've got those items installed correctly by using these commands in your terminal:
pip show cs50
flask --version
werkzeug --version
If they're installed, but you haven't quit and restarted VS Code, try that.
If you're using a virtual environment, make sure you reactivate it before trying to run your application.
I hope one of these helps solve your problem!

Confused about Python installations, module installation, and interpreter

So yesterday I had to create a virtualenv in order to be able to install Python modules that wouldn't install thanks to OS X El Capitan's new SIP. I thought I did everything right, but today I'm reaching a different conclusion. I hope I can be clear about it.
my python custom install is at myname/learnp/imdb_module, this is where I created it with virtualenv. Edit: I later moved it to myname/learnp/ayr2/imdb_module.
However, when I try to run the interpreter, it seems to always default to the Python that is in Library or something along these lines. I found out about this because a certain module that I managed to install in this custom python env wouldn't import, when I checked what modules I have, it wasn't the same as what I expected.
Furthermore, it seems that ALL other modules that I wanted to install on the CUSTOM virtualenv were installed on the main python env, and that I wasn't installing those modules on the custom env all along.
Excuse me, but I'm very confused right now.
I know how to create a virtual env
I know how to activate it (it appears to the right on Terminal line)
I don't know how to install modules to my virtual env
I don't know how to make the interpreter run from the virtual env so I can do python operations that are only possible by using custom env modules
Any advice is much appreciated!
Update:
Followed Will Hogan's answer for troubleshooting,and I think something weird is happening, quoting my comment to his answer:
HI, thanks for taking the time to answer. This is basically the way I understood this. However, let me attach a screenshot: http://i.imgur.com/DfpngJq.jpg . Am I right to assume something is wrong here? My prompt is changed with the virtualenv named "imdb_module", but when I type in which python it doesn't list ayr2/imdb_module/bin but rather a folder with the path usr/bin/python, which if I understand correctly is the "default" environment.
And not if this helps in any way, but echo $PATH when (imdv_module) appears to the right of the prompt, gives this (I redacted my name): /Users/REDACTEDNAME/learnp/imdb_module/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
While creating the virtualenv you should see it installing setuptools and pip:
$ virtualenv testvenv
New python executable in testvenv/bin/python2.7
Also creating executable in testvenv/bin/python
Installing setuptools, pip...done.
After ensuring the virtualenv is activated you should see your prompt change:
$ . ./testvenv/bin/activate
(testvenv)$
Now you can confirm the paths to python and pip, which should be in the virtualenv:
(testvenv)$ which python
/private/tmp/testvenv/bin/python
(testvenv)$ which pip
/private/tmp/testvenv/bin/pip
If you aren't seeing the python and pip locations as being under the virtualenv's directory, then the virtualenv has not been activated.
I would also ensure that, if you're executing the .py file directly (and not with "python foo.py"), that your shebang line uses:
#!/usr/bin/env python
Or even the full path to the virtualenv's python, e.g.:
#!/tmp/testvenv/bin/python
As opposed to, say:
#!/usr/bin/python
The first will search in the current environment, which will be set by the virtualenv activation. The second explicitly points to the virtualenv's `python'.

Django installation - virtualenv.py errors out

I am trying to create a Virtual Environment for my django site.
Command is below. but it says "You must provide a DEST_DIR" though I have given the directory name "SOWL".
virtualenv.py SOWL --no-site-packages
http://screencast.com/t/rej893zrg
I have spent half a day on this. I can't find anything on google search either.
Any help is much appreciated.
Thanks,
SHM
At first glance your command is out of order; the flags come first, directory last. However it doesn't seem to matter; the command, as you ran it, works for me on Mac and Windows.
I'd guess the problem lies with your installation of virtualenv. Virtualenv is also one of those tools that never seems to get updated. Make sure you have the latest. Install with pip (first choice) or if you need the actual virtualenv.py file, either way the instructions are here.
UPDATE Here's an install-Python-in-Windows guide. I know you already have Python, but this will make sure your PATH is setup and get you PIP and Virtualenv as well.
Install Python using the Windows installer
Add this to your PATH environment variable: C:\Python27\;C:\Python27\Scripts\
Get Distribute by downloading the distribute_setup.py file. (There is no Windows installer; the script does it all.)
Get PIP by downloading the get-pip.py file.
python distribute_setup.py
python get-pip.py
pip install virtualenv
Now you are set with virtualenv. However there's more — the virtualenvwrapper makes life easy. It's only for bash shells, but there's a Windows port here. There are installation instructions, tips and a rundown of the nifty new commands that the wrapper gives you.
pip install virtualenvwrapper-win
pyassoc
Create a new environment variable: WORKON_HOME=%USERPROFILE%\Envs
Now you can do this to create your virtualenv (and notice the prompt change to indicate which env you are in):
mkvirtualenv --distribute SOWL
>>>(SOWL) C:\Users\User>
I think your parameters are just out of order. Did you try
virtualenv.py --no-site-packages SOWL

Categories