Virtualenv won't create environment; runtime error - python

I'm trying to create a simple virtualenv environment; python and virtualenv are both installed. When I go in to my directory in which I am trying to make this environment, I keep getting a Windows Script Host popup box:
Script: *My path to virtualenv.js*
Line: 1
Char: 1
Error: Object expected
Code: 800A138F
Source: Microsoft JScript runtime error
I went in to my file to see where the problem may have lied and assumed it was just a module I hadn't installed yet, though all of them are in the node_modules in my package. I'm not sure where else this issue is coming from?

It looks to me as if you have a virtualenv.js JavaScript file on your path, and that JS files are associated with Windows Scripting Host on your machine. (Perhaps you have the node-virtualenv project installed, which puts a JavaScript file with the name virtualenv.js in your path?)
To create a typical Python virtual environment, you want to invoke the (Python) virtualenv.py script. Assuming you've installed virtual environment with:
pip install virtualenv
Then you can use:
python -m virtualenv ENV
to invoke the Python interpreter directly, and have it load the appropriate virtualenv.py script file on your path.

Related

How do I ensure python project in VSCODE is using virutal envirnoment and not defaulting to global?

Having an issue when using flask and flask-wtf. The issue is that for some reason vscode is defaulting to global rather than the newly created virtual environment. In vscode I will click open folder, create the folder and open it in vscode. Then I'll write my code out and then open terminal in vscode and write: python -m venv my_venv, then on the lower left-hand side I will select it as my virtual environment. I then re-open the terminal, write: pip -V and the pip it is directed to is the folder directory with my_venv in the path name.
Then I pip install flask and flask-wtf, check that they are installed with pip list. Everything looks good until I run and vscode says: ModuleNotFoundError: No module named 'flask-wtf'. But when I go to my global environment and where flask is installed too it runs fine. Something is happening to where the python code is recognizing the original flask and not the one in my virtual environment. How do I ensure that the version of flask is the one in the virtual environment and not others installed on my machine.
Thanks
If you are in your terminal in vscode, it should append your command line with your virtual environment name.
So, usually it would show
PS \path
But if your environment is running, it will show
(venv name) PS \path
If it is now showing, be sure to reactivate your virtual environment from your project directory

no python at "C:\Users\AccountName\AppData\Local\Programs\Python\Python38-32\python.exe" error in VsCode

I was running the Django project without any problems. Until I reinstalled Windows and then reinstalled vscode! Now that I am running the Django project, vscode shows the following error:
Error: no python at C:\Users\AccountName\AppData\Local\Programs\Python\Python38-32\python.exe
This might be occurs if the python directory still in the environment variables path list.
First remove python entry from the environment variables path if exists.
Also there will be a chance for virtual environments in your project. If the virtual environment is setup in the uninstalled python version then you will get the same error message.
So, remove the virtual environments which is created under the uninstalled python. It can be done by deleting the virtual environment folder from your system.
Edit pyvenv.cfg
home = C:\Users\UserName\AppData\Local\Programs\Python\Python38-32
include-system-site-packages = false
version = 3.8.3
When I edited this file after checking the file path on my computer, it worked for me.
Based on the information you provided, it is recommended that you check the Python environment variables.
Since the Windows system is reinstalled, the environment variables are restored to the default settings. Therefore, please add Python environment variables:
Or you can reinstall Python and check the "Add Python 3.8 to PATH" option, which will automatically add Python environment variables.
You could also refer to : Python environment variables.
It's very simple
Delete your dbsqite3 file from your project folder
Open your project in CMD
install virtual environment pip install virtaualenv
virtualenv .
\scripts\activate
python manage.py runserver
and play with your code
you shared.
This works for Pycharm, It did to me
From your projects folder, delete the 3 folders i.e. .ide,venv, and the third folder i think.. do not touch the projects or scripts you created. After wards, go to Pycharm and configure python interpreter again. This will now enable you to run yo scripts now with no prob
make sure to install virtualenv befor install python
check wheather django is installed (if your are using django framework).
pip install django

How to include python==3 with virtual environment of python module

I am creating python bundle for a client. I want to add python==3.7 also with that bundle so the user need not to install python on windows platform.
Created Virtual environment and copied that to new pc (without python install) and opened python from venv/Script/Python.exe.
But got error of missing dll files
I expect a bat file containing python.exe address from venv folder and running python file using venv python.exe or something like this

Python virtualenv activation working but interpreter doesn't

I've just setup a new environment for my project and uploaded a python repository including bin, lib and project folder. I'm pretty sure I did same previously and it worked without problem. Now when doing the same on an AWS environment I get the error
-bash: /projects/scrapy/bin/python2.7: cannot execute binary file. However when doing source /projects/scrapy/bin/activate it successfully activates the environment.
From what I understand, python should be able to execute without any issue no matter the environment ?
Any help or pointing to the right direction would be much appreciated!
python should be able to execute without any issue no matter the environment ?
No, the Python binary is tied to your specific OS and computer architecture. Python source code can usually be run on different machines (provided you didn't use OS-specific features), but that's only made possible by compiling a Python interpreter for the specific target environment first.
In other words, a Python binary compiled to run on macOS will not work on Linux.
All that source bin/activate achieves is that it configures your terminal setting to use the bin directory as the first directory on the PATH search path. This doesn't make bin/python work in another environment, it just means that both environments have a working shell interpreter that can run that script.
Create a new virtualenv with a Python binary compiled for Linux, and install the same packages there. Use Pipenv or a requirements.txt file to transfer the dependencies from Mac to Linux.
For example, using Pipenv you'd copy over the Pipfile and Pipfile.lock files to the other computer, then run pipenv install in the directory there and re-create the virtualenv and dependencies from those files.
I recommend you read up on Python development best practices in the The Hitchhiker’s Guide to Python; this includes such topics on how to manage an environment for a project.

Copy Python project folder to computer without python, can I run it?

So I develop a python application and I plan to copy the whole folder for my friend to use it as end-user.
But my friend does not have python installed in the computer and I don't want to make them install it since he is not a developer.
In my project I have set up the virtualenv with python.exe inside it but without the site-packages, and I copy the virtualenv together with the project folder.
Is it possible to do this kind of setup so the application in the other end runs without python installed?
virtualenv is a good option if you are transferring the folder between two same operating systems.
In order to include the correspond site packages that are already installed in your computer, install them inside the virtualenv context by doing pip install in the virtualenv shell.
You could use pip freeze to get a list of installed python packages from your computer.
You could then include a .bat file (if it is a windows system) or .sh file (if its a linux system) so it would run your script with the virtualenv context.

Categories